In our end-to-end tests, we dynamically generate the URL endpoint for us to test against. In our Protractor configuration, I was hoping to use beforeLaunch or onPrepare to retrieve the URL endpoint and set it to baseUrl before running our tests. However it seems no matter what I try, Protractor runs tests with the wrong baseUrl, not the one I set in beforeLaunch or onPrepare.
We're using Protractor version 1.4.0. This is a simple configuration file demonstrating the issue:
exports.config =
directConnect: true
framework: 'jasmine'
jasmineNodeOpts:
isVerbose: true
showColors: true
includeStackTrace: true
suites:
login: 'login/**/*.coffee'
full: '**/*.coffee'
capabilities:
browserName: 'chrome'
beforeLaunch: ->
setBaseUrl 'https://test-url.com'
onPrepare: ->
setBaseUrl 'https://test-url.com'
setBaseUrl = (baseUrl) ->
exports.config.baseUrl = baseUrl
Thanks for the help!
It looks like calling browser.baseUrl = "https://test-url.com" does the trick in onPrepare
Related
I'm new testing with protractor, but I cant run my tests.
My protractor.config.js:
exports.config = {
allScriptsTimeout: 99999,
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
baseUrl: 'http://localhost:8080/',
framework: 'jasmine',
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['.src/test/e2e/login.e2e.spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
includeStackTrace: true
}
};
and this is the test I'm trying to run:
'use strict';
describe('my app', function() {
beforeEach(function () {
browser.get('index.html');
});
it('should automatically redirect to / when location hash is empty', function() {
expect(browser.getLocationAbsUrl()).toMatch("/");
});
});
And this is the error I get:
I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[13:20:49] I/launcher - Running 1 instances of WebDriver
Started
No specs found
Finished in 0.001 seconds
[13:20:50] I/launcher - 0 instance(s) of WebDriver still running
[13:20:50] I/launcher - chrome #01 passed
[13:20:50] The following tasks did not complete: e2e
[13:20:50] Did you forget to signal async completion?
I'm running webdriver-manager and my app server. My jasmine version is: 2.5.2
and my protractor version is:
4.0.9
Any idea of what I'm doing wrong??
Thanks!!!
I realized what was my problem (thanks to the comments that helped me to realize).
I was running my test with a gulp task I made:
function e2e() {
gulp.src(["/src/test/*.js"]).pipe(protractor({
configFile: "conf/protractor.config.js",
args: ['--baseUrl', 'http://localhost8080']
})).on('error', function (e) {
throw e;
});
}
I dont know why this: gulp.src(["/src/test/*.js"])wasnt getting to acces to my test files, so I changed it for: gulp.src(["src/test/e2e/login.e2e.spec.js"])
I know its not the best solution,but enough to survive...
I am trying to use protractor html screenshot reporter but it's failing to require in the the config file. Here's my config:
//Configuration for Protractor
var HtmlReporter = require('protractor-html-screenshot-reporter');
var reporter = new HtmlReporter({
baseDirectory: '/screenshots',
takeScreeenShotOnlyForFailedSpecs: true
});
exports.config = {
//Address of Selenium server
seleniumAddress: 'http://localhost:4444/wd/hub',
//framework: 'jasmine2',
chromeOnly: false,
multiCapabilities: [
{'browserName': 'chrome'}
],
//URL of the application
baseUrl: 'http://localhost:80',
cache: false,
//Spec pattern
specs: ['**/specs/*-spec.js'],
onPrepare: function () {
//browser.driver.manage().window().maximize();
browser.driver.manage().window().setSize(480, 800);
browser.driver.manage().window().setPosition(400, 100);
jasmine.getEnv().addReporter(reporter);
},
//Options passed to Jasmine-node
jasmineNodeOpts: {
includeStackTrace: true,
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
}
};
I have both protractor and the protractor html screenshot report installed globally . Here's the error protractor is throwing:
[13:48:23] E/configParser - error code: 105
[13:48:23] E/configParser - description: failed loading configuration file protractor-config.js
Any help would be most helpful!!
UPDATE:
I moved to the require call inside the onPrepare in the config and I getting the proper error:
[14:27:15] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[14:27:15] I/launcher - Running 1 instances of WebDriver
[14:27:18] E/launcher - Error: Error: Cannot find module 'protractor-html-screenshot-reporter'
Seems like it can't find the node module. Anyone else seeing this issue?
UPDATE2:
So, I think I found my problem. I was installing like this:
npm install -g protractor-html-screenshot-reporter
Which seems to be the cause the fail. Installing with this command:
npm install protractor-html-screenshot-reporter --save-dev
Works! For whatever reason installing globally doesn't work but installing locally does, which is a bit of a downer :( If anyone knows how to get this to work with the screenshot reporter installed globally let me know how :)
My protractor conf looks like this:
exports.config = {
seleniumServerJar: "../node_modules/protractor/selenium/selenium-server-standalone-2.51.0.jar",
seleniumPort: 4444,
baseUrl: baseUrl,
specs: specs,
untrackOutstandingTimeouts:true,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 3600000
},
framework: "jasmine2"
}
I am trying perform action on angular page but fails with error -
Failed: Timed out waiting for Protractor to synchronize with the page after 150 seconds.
Please see https://github.com/angular/protractor/blob/master/docs/faq.md.
The following tasks were pending:
- $http: /api/v1/query/tail/242ac110002-8/1h?t=1456925874600
I have added untrackOutstandingTimeouts:true in protractor conf, still I am getting above error.
Protractor Version - 3.1.1
Node version - 4.3.1
Selenium-webdriver - 2.51.0
Thanks in advance!
Able to solve above problem using browser.ignoreSynchronization
browser.get('/');
browser.ignoreSynchronization=true;
//Go to page where $http and $timeout is added
//Perform any action, steps here
browser.sleep(5000); //This can be replace with wait condition
browser.ignoresynchronization=false
I am new to protractor testing tool in angular js, I installed CORS extension
in chrome browser, I wrote my first test-case, I try to run this using
'protractor config.js' chrome browser is getting open, actually it is login form, i entered correct username and password but it is not connecting to server, I understood that CORS extension was disabled, how to enable cors extension when i am running test case through cmd.
my config.js
exports.config = {
capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE (-_-)
'browserName': 'chrome'
},
specs: [
// We are going to make this file in a minute
'../www/modules/user/login.spec.js',
//'../www/modules/lead/list.spec.js',
],
jasmineNodeOpts: {
showColors: true,
//defaultTimeoutInterval: 30000,
isVerbose: true,
},
allScriptsTimeout: 20000,
onPrepare: function(){
browser.driver.get('http://localhost:8100/');
}
};
By default, a completely clean browser is fired up with no extensions installed.
In order to start Chrome with an extension, you need to set the chromeOptions and the extensions appropriately. Here you can find working samples:
Is it possible to add a plugin to chromedriver under a protractor test?
just change capabilities section. or u can follow alexe answer.
capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE (-_-)
'browserName': 'chrome',
chromeOptions': { 'args': ['--disable-web-security'] }
},
I have an idea to make my configs more flexible. For example I have 10000 config files with same parameters:
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['C:/Users/Lilia.Sapurina/Desktop/Protractor Tests/Scenarios/ps-grid-column-filter-range_spec.js'],
params: {'url_filter': 'http://wks-15103:8010/ps/ng-components/examples/ps-grid-column-filter-range.html'}
And once I want to change path to specs, html or change selenium address. Can I do this in another file for all my configs?
For example write in my config:
seleniumAddress: '../Variables/seleniumAdress.txt'
Or maybe exist another interesting ways to solve this problem?
You can export your common config rules as node.js module:
// globalProtractor.conf.js
module.exports = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['C:/Users/Lilia.Sapurina/Desktop/Protractor Tests/Scenarios/ps-grid-column-filter-range_spec.js'],
params: {
'url_filter': 'http://wks-15103:8010/ps/ng-components/examples/ps-grid-column-filter-range.html'
}
And use in another file
// protractor.conf.js
var globalConf = require('/path/to/globalProtractor.conf.js');
globalConf.specs.push('path/new.spec.js');
exports.config = globalConf;
With #driver_by help I found nice solution for my problem. Now my files isolated. If I want to change url or path to folder I should change only global config.
// globalProtractor.conf.js
module.exports = {
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://wks-15103:8010/ps/ng-components/examples/',
specs: [],
path_to_scenario: '../Scenarios/',
path_to_spec: '../Specs/',
path_to_lib: '../Lib/'
}
And another file:
// protractor.conf.js
var globalConf = require('../Global_configs/globalProtractor_conf.js');
globalConf.specs.push(path_to_spec + 'ps-grid-column-filter-range_spec.js');
globalConf.params = {'url_filter': 'ps-grid-column-filter-range.html',
'column_number_filter': 5,
'req_lib_filter': globalConf.path_to_lib + 'jasmine-expect'}
exports.config = globalConf;