mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
parent
495e291d4f
commit
eb7104cb85
4 changed files with 28 additions and 8 deletions
|
@ -43,7 +43,7 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|||
end
|
||||
|
||||
it "height should be at least 10px" do
|
||||
@image[:height].should >= 10
|
||||
@image[:height].should be >= 10
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,7 +55,12 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|||
end
|
||||
|
||||
it "height should match the height given" do
|
||||
@image[:height].should > 10
|
||||
@image[:height].should == 400
|
||||
end
|
||||
|
||||
it "should reset window dimensions to their default value" do
|
||||
driver.evaluate_script('window.innerWidth').should == 1680
|
||||
driver.evaluate_script('window.innerHeight').should == 1050
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,11 +68,26 @@ describe Capybara::Webkit::Driver, "rendering an image" do
|
|||
before { render(:width => 50, :height => 10) }
|
||||
|
||||
it "width should be greater than the width given" do
|
||||
@image[:width].should > 50
|
||||
@image[:width].should be > 50
|
||||
end
|
||||
|
||||
it "height should be greater than the height given" do
|
||||
@image[:height].should > 10
|
||||
@image[:height].should be > 10
|
||||
end
|
||||
|
||||
it "should restore viewport dimensions after rendering" do
|
||||
driver.evaluate_script('window.innerWidth').should == 1680
|
||||
driver.evaluate_script('window.innerHeight').should == 1050
|
||||
end
|
||||
end
|
||||
|
||||
context "with a custom viewport size" do
|
||||
before { driver.resize_window(800, 600) }
|
||||
|
||||
it "should restore viewport dimensions after rendering" do
|
||||
render({})
|
||||
driver.evaluate_script('window.innerWidth').should == 800
|
||||
driver.evaluate_script('window.innerHeight').should == 600
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,9 +11,8 @@ void Render::start() {
|
|||
int height = arguments()[2].toInt();
|
||||
|
||||
QSize size(width, height);
|
||||
page()->setViewportSize(size);
|
||||
|
||||
bool result = page()->render( imagePath );
|
||||
bool result = page()->render( imagePath, size );
|
||||
|
||||
emitFinished(result);
|
||||
}
|
||||
|
|
|
@ -193,12 +193,13 @@ QString WebPage::failureString() {
|
|||
return message + m_errorPageMessage;
|
||||
}
|
||||
|
||||
bool WebPage::render(const QString &fileName) {
|
||||
bool WebPage::render(const QString &fileName, const QSize &minimumSize) {
|
||||
QFileInfo fileInfo(fileName);
|
||||
QDir dir;
|
||||
dir.mkpath(fileInfo.absolutePath());
|
||||
|
||||
QSize viewportSize = this->viewportSize();
|
||||
this->setViewportSize(minimumSize);
|
||||
QSize pageSize = this->mainFrame()->contentsSize();
|
||||
if (pageSize.isEmpty()) {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ class WebPage : public QWebPage {
|
|||
void setPromptText(QString action);
|
||||
int getLastStatus();
|
||||
void setCustomNetworkAccessManager();
|
||||
bool render(const QString &fileName);
|
||||
bool render(const QString &fileName, const QSize &minimumSize);
|
||||
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
|
||||
void setSkipImageLoading(bool skip);
|
||||
QVariantList consoleMessages();
|
||||
|
|
Loading…
Reference in a new issue