Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Start phantomjs maximized
Browse files Browse the repository at this point in the history
Default windows size of size phantomjs does not allow
some shadows on the edges of elements to fit in the
crop rectangle. This can be fixed by maximizing
the window.
Other browsers does not have such a problem, so
they are started the same way as before.
  • Loading branch information
Sergey Tatarintsev committed Apr 7, 2014
1 parent d7acde4 commit ac0549e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
10 changes: 8 additions & 2 deletions lib/browser/element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

var inherit = require('inherit'),
var util = require('util'),
inherit = require('inherit'),
Rect = require('../geometery/rect');

module.exports = inherit({
__constructor: function(wdElement) {
__constructor: function(selector, wdElement) {
this.selector = selector;
this._wdElement = wdElement;
},

Expand All @@ -24,5 +26,9 @@ module.exports = inherit({

isVisible: function() {
return this._wdElement.isDisplayed();
},

toString: function() {
return util.format('[object Element(selector=\'%s\')]', this.selector);
}
});
47 changes: 34 additions & 13 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,39 @@ module.exports = inherit({

open: function(url) {
var _this = this;
return this._browser.init({browserName: this.name}).then(function() {
return _this._browser.get(url);
})
.fail(function(e) {
if (e.code === 'ECONNREFUSED') {
return q.reject(new GeminiError(
'Unable to connect to ' + _this.config.gridUrl,
'Make sure that URL in config file is correct and selenium\nserver is running.'
));
}
return q.reject(e);
});
return this._browser.init({browserName: this.name})
.then(function() {
return _this._browser.get(url);
})
.then(function() {
//maximize is required, because default
//windows size in phantomjs can prevent
//some shadows from fitting in
if (_this._shouldMaximize()) {
return _this._maximize();
}
})
.fail(function(e) {
if (e.code === 'ECONNREFUSED') {
return q.reject(new GeminiError(
'Unable to connect to ' + _this.config.gridUrl,
'Make sure that URL in config file is correct and selenium\nserver is running.'
));
}
return q.reject(e);
});
},

_shouldMaximize: function() {
return this.name === 'phantomjs';
},

_maximize: function() {
var _this = this;
return _this._browser.windowHandle()
.then(function(handle) {
return _this._browser.maximize(handle);
});
},

buildElementsMap: function(staticSelectors, dynamicSelectors) {
Expand Down Expand Up @@ -61,7 +82,7 @@ module.exports = inherit({
_findElement: function(selector, optional) {
return this._browser.elementByCssSelector(selector)
.then(function(wdElement) {
return new Element(wdElement);
return new Element(selector, wdElement);
})
.fail(function(error) {
if (optional && error.status === 7) { //element not found
Expand Down

0 comments on commit ac0549e

Please sign in to comment.