Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noptor: restart browser #316

Open
wants to merge 4 commits into
base: noptor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ Execute the visual test:
$ uiveri5 --browsers=browser:*:android --seleniumAddress=http://127.0.0.1:4723/wd/hub --baseUrl=http://10.0.2.2:8080
```

## Browser instances
Use `restartBrowserBetweenSpecs` to restart the browser between every spec file. Defaults to false:
```javascript
exports.config = {
restartBrowserBetweenSpecs: true,
browsers: [{
browserName: "chrome"
}]
}
```

Use `maxInstances` to run every spec file in a separate browser parallely. Up to `maxInstances` browsers will be running at any given moment.
When a spec is done, the browser instance is destroyed and a new browser is started.
Defaults to 1 - run one browser at a time.
```javascript
exports.config = {
maxInstances: 5,
browsers: [{
browserName: "chrome"
}]
}
```
2 changes: 1 addition & 1 deletion e2e/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = class Runner {
var cmdString = [
'node',
'../bin/uiveri5',
'-v',
'--v',
'--browsers=chromeHeadless',
'--config.specResolver="./resolver/localSpecResolver"',
'--config.specs=' + opts.specs,
Expand Down
5 changes: 2 additions & 3 deletions spec/StatisticCollector.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

describe("StatisticCollector", function() {
var reporter;
var reporter = require('../src/statisticCollector');

beforeEach(function(){
reporter = require('../src/statisticCollector')();
reporter.reset();
});

describe("getOverview", function () {
Expand Down
15 changes: 7 additions & 8 deletions spec/localComparisonProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var LocalComparisonProvider = require('../src/image/localComparisonProvider.js')

describe("LocalComparisonProvider", function () {
var logger = require('../src/logger');
var matchers = {};
var imagePath = '/localComparisonProvider/images/testSpec/platform/resolution/browser/theme/direction/mode';

function takeScreenshotMock(name){
Expand Down Expand Up @@ -58,7 +57,7 @@ describe("LocalComparisonProvider", function () {
it('Should pass with similar images', function (done) {
var comparisonProvider = new LocalComparisonProvider(
comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('arrow_left'),'arrow_left');
result.pass.then(
Expand All @@ -72,7 +71,7 @@ describe("LocalComparisonProvider", function () {
it('Should fail with different images', function(done) {
var comparisonProvider = new LocalComparisonProvider(
comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('arrow_left_hover'),'arrow_left');
result.pass.then(
Expand All @@ -89,7 +88,7 @@ describe("LocalComparisonProvider", function () {
comparisonConfig.thresholdPercentage = 0.75;

var comparisonProvider = new LocalComparisonProvider(comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('drop_down_draw'),'drop_down_clean');
result.pass.then(
Expand All @@ -105,7 +104,7 @@ describe("LocalComparisonProvider", function () {
comparisonConfig.thresholdPercentage = 0.1;

var comparisonProvider = new LocalComparisonProvider(comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('drop_down_draw'),'drop_down_clean');
result.pass.then(
Expand All @@ -121,7 +120,7 @@ describe("LocalComparisonProvider", function () {
comparisonConfig.thresholdPercentage = 0.75;

var comparisonProvider = new LocalComparisonProvider(comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('drop_down_draw'),'drop_down_clean');
result.pass.then(
Expand All @@ -136,7 +135,7 @@ describe("LocalComparisonProvider", function () {
comparisonConfig.ignoreNothing = true;

var comparisonProvider = new LocalComparisonProvider(comparisonConfig,comparisonInstanceConfig,logger,storageProvider);
comparisonProvider.register(matchers);
var matchers = comparisonProvider.getMatchers();

var result = matchers.toLookAs().compare(takeScreenshotMock('calendar_act'),'calendar_ref');
result.pass.then(function(passed){
Expand All @@ -149,8 +148,8 @@ describe("LocalComparisonProvider", function () {
var invalidBuffer = new Buffer('not an actual png', 'utf8');
var comparisonProvider = new LocalComparisonProvider(
comparisonConfig, comparisonInstanceConfig, logger, storageProvider);
var matchers = comparisonProvider.getMatchers();

comparisonProvider.register(matchers);
var result = matchers.toLookAs().compare(invalidBuffer, 'arrow_left');
result.pass.then(function (passed) {
expect(passed).toBe(false);
Expand Down
6 changes: 4 additions & 2 deletions src/api/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var should = require('should').noConflict();

module.exports = function(){
return {
register: function(matchers) {
getMatchers: function() {
var body = function() {
return {
compare: function(actualResponse, expectedFn) {
Expand All @@ -22,7 +22,9 @@ module.exports = function(){
}
};
};
matchers.body = body;
return {
body: body
};
}
};
};
6 changes: 4 additions & 2 deletions src/api/toHaveHttpBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function ToHaveHttpBody(){

}

ToHaveHttpBody.prototype.register = function(matchers) {
ToHaveHttpBody.prototype.getMatchers = function () {
var toHaveHTTPBody = function() {
return {
compare: function(actualResponse, expectedResponse) {
Expand All @@ -24,7 +24,9 @@ ToHaveHttpBody.prototype.register = function(matchers) {
};
};

matchers.toHaveHTTPBody = toHaveHTTPBody;
return {
toHaveHTTPBody: toHaveHTTPBody
};
};

module.exports = function(){
Expand Down
8 changes: 5 additions & 3 deletions src/api/toHaveHttpHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ function ToHaveHttpHeader(){

}

ToHaveHttpHeader.prototype.register = function(matchers) {
var toHaveHTTPHeader = function() {
ToHaveHttpHeader.prototype.getMatchers = function () {
var toHaveHTTPHeader = function () {
return {
compare: function(actualResponse, expectedResponse) {
var result = {};
Expand All @@ -31,7 +31,9 @@ ToHaveHttpHeader.prototype.register = function(matchers) {
};
};

matchers.toHaveHTTPHeader = toHaveHTTPHeader;
return {
toHaveHTTPHeader: toHaveHTTPHeader
};
};

module.exports = function(){
Expand Down
24 changes: 20 additions & 4 deletions src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ var expectedConditions = require('../element/expectedConditions');
var logger = require('../logger');
var elementUtil = require('./elementUtil');
var clientsideScripts = require('../scripts/clientsidescripts');
var statisticCollector = require('../statisticCollector');

var DEFAULT_RESET_URL = 'data:text/html,<html></html>';
var DEFAULT_GET_PAGE_TIMEOUT = 10000;
var AUTH_CONFIG_NAME = 'auth';

/**
* @alias browser
Expand Down Expand Up @@ -88,11 +90,25 @@ var Browser = function (webdriverInstance, opt_baseUrl) {
},
navigation: {
waitForRedirect: browser._waitForRedirect.bind(browser),
// expose navigation helpers to tests
to: browser._navigateTo.bind(browser),
_getAuthenticator: function () {
// override in uiveri5.js - needs moduleLoader and statisticCollector
return null;
}
_getAuthenticator: function (authConfig) {
var moduleLoader = require('../moduleLoader')(this.testrunner.config);
var authenticator;
if (authConfig) {
// programatically invoked authentication - load auth module every time
authenticator = moduleLoader.loadNamedModule(authConfig, [statisticCollector]);
} else {
// if auth is declared in config, load the (global) auth module only once.
// when authOnce is enabled, auth should be done only once - before the first spec file.
if (this.authenticator) {
authenticator = this.testrunner.config.authOnce ? null : this.authenticator;
} else {
authenticator = this.authenticator = moduleLoader.loadNamedModule(AUTH_CONFIG_NAME, [statisticCollector]);
}
}
return authenticator;
}.bind(this)
}
};

Expand Down
59 changes: 59 additions & 0 deletions src/configUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var _ = require('lodash');
var logger = require('./logger');

module.exports = {
logFrameworkVersion: function () {
var pjson = require('../package.json');
logger.info(pjson.name + ' v' + pjson.version);
},

getOSType: function () {
var os = require('os');
var osType = '';

if (os.type() == 'Darwin') {
osType = 'mac64';
} else if (os.type() == 'Linux') {
if (os.arch() == 'x64') {
osType = 'linux64';
} else {
osType = 'linux32';
}
} else if (os.type() == 'Windows_NT') {
osType = 'win32';
} else {
osType = 'unknown';
}

return osType;
},

copyTimeouts: function (launcherArgv, config) {
if (config.timeouts) {
if (config.timeouts.getPageTimeout) {
var getPageTimeout = config.timeouts.getPageTimeout;
if (_.isString(getPageTimeout)) {
getPageTimeout = parseInt(getPageTimeout, 10);
}
logger.debug('Setting getPageTimeout: ' + getPageTimeout);
launcherArgv.getPageTimeout = getPageTimeout;
}
if (config.timeouts.allScriptsTimeout) {
var allScriptsTimeout = config.timeouts.allScriptsTimeout;
if (_.isString(allScriptsTimeout)) {
allScriptsTimeout = parseInt(allScriptsTimeout, 10);
}
logger.debug('Setting allScriptsTimeout: ' + allScriptsTimeout);
launcherArgv.allScriptsTimeout = allScriptsTimeout;
}
if (config.timeouts.defaultTimeoutInterval) {
var defaultTimeoutInterval = config.timeouts.defaultTimeoutInterval;
if (_.isString(defaultTimeoutInterval)) {
defaultTimeoutInterval = parseInt(defaultTimeoutInterval, 10);
}
logger.debug('Setting defaultTimeoutInterval: ' + defaultTimeoutInterval);
launcherArgv.jasmineNodeOpts.defaultTimeoutInterval = defaultTimeoutInterval;
}
}
}
};
22 changes: 22 additions & 0 deletions src/connection/connectionProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var DEFAULT_CONNECTION_NAME = 'direct';
var connection;

var ConnectionProvider = function () { };

ConnectionProvider.prototype.verifyConfig = function (config) {
var connectionName = config.connection || DEFAULT_CONNECTION_NAME;
var connectionConfig = config.connectionConfigs[connectionName];
if (!connectionConfig) {
throw Error('Could not find connection: ' + connectionName);
}
};

ConnectionProvider.prototype.setConnection = function (connectionModule) {
connection = connectionModule;
};

ConnectionProvider.prototype.getConnection = function () {
return connection;
};

module.exports = new ConnectionProvider();
Loading