I am trying to run basic end to end tests written using protractor. I always get this error.
ScriptTimeoutError: Timed out
I checked this link https://github.com/angular/protractor/blob/master/docs/timeouts.md and increased the default timeout, but still I get the same error. I am not able to figure out from where this error pops out. The browser loads the base Url, later it will not perform any action as mentioned in the test. The test is very simple , open the browser and click on the menu and verify if the URL is matched.
Node Version: v7.5.0
Protractor Version: 5.1.2
Angular Version: 2.4.10
Browser(s): firefox
Operating System and Version ubuntu
typescript: 2.2.2
Config file
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test/e2e/menu.js'],
capabilities: {
'browserName': 'firefox',
},
baseUrl: 'http://localhost:8100/#/',
//allScriptsTimeout: 360000,
jasmineNodeOpts: {
showColors: true,
// defaultTimeoutInterval: 360000
},
//useAllAngular2AppRoots:true,
//menu.js
describe('menu check', function () {
beforeEach(function () {
browser.get('http://localhost:8100/#/');
browser.waitForAngular();
// browser.driver.manage().timeouts().setScriptTimeout(60000);
});
it('Should route to the operationalView page from menu', function () {
element(by.css('[href="#/operationalView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/operationalView');
});
it('Should route to the worldlview page from menu', function () {
element(by.css('[href="#/worldView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/worldView');
});
});
I have had this issue once, which I resolved using
browser.ignoreSynchronization=true
before the beforeEach() method in your Protractor spec files. This makes Protractor not wait for Angular promises, such as those from $http or $timeout to resolve. You can try this in your script.
Edit : As of today, 08/16/19, this solution has been deprecated. Use waitForAngularEnabled to be false instead.
Related
I am novice user of protractor and trying to use it for angularjs application,
Config file snippet :
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['plugins/./test_spec.js'],
allScriptsTimeout: 60000,
getPageTimeout: 30000,
jasmineNodeOpts: {
defaultTimeoutInterval: 1240000
}
};
Working test case (spec file):
describe('Login', function () {
it('Login Page', function () {
browser.get('http://localhost:9000/apps/admin/');
element(by.model('ctrl.user.name'))
element(by.model('ctrl.user.password'))
expect(true).toBe(true)
});
});
Failing test case (spec file):
describe('Login', function () {
it('Login Page', function () {
browser.get('http://localhost:9000/apps/admin/');
element(by.model('ctrl.user.name')).sendKeys("test1");
element(by.model('ctrl.user.password')).sendKeys("test1");
element(by.css('[type="submit"]')).click();
expect(true).toBe(true)
});
});
Trying to use sendKeys for login page is failing but without sendkeys test case passes, I am getting following error:
Failed: script timeout: result was not received in 60 seconds
(Session info: chrome = 72.0.3626.109)
(Driver info: chromedriver = 2.46.628402(536cd7adbad73a3783fdc2cab92ab2ba7ec361e1), platform = Windows NT 10.0.17134 x86_64)
I suspect element not being found.
Please guide me through this.
Thanks in Advance
I highly recommended to add SELENIUM_PROMISE_MANAGER: false, to your protractor.config file due to this thread, if tells it shortly - better to don't use Control Flow. So how will look your config file:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['plugins/./test_spec.js'],
allScriptsTimeout: 60000,
getPageTimeout: 30000,
jasmineNodeOpts: {
defaultTimeoutInterval: 1240000
},
SELENIUM_PROMISE_MANAGER: false,
};
After it you should update your tests (all actions that returns promise should resolve it, I prefer async ... await style). Also, your expect true is useless, let get rid off it, and add some explicit waiters.
describe('Login', () => {
it('Login Page' async () => {
await browser.get('http://localhost:9000/apps/admin/');
const name = element(by.model('ctrl.user.name'));
await browser.wait(ExpectedConditions.elementToBeClickable(name), 10000);
await name.sendKeys("test1");
const password = element(by.model('ctrl.user.password'));
await browser.wait(ExpectedConditions.elementToBeClickable(password), 10000);
await password.sendKeys("test1");
element(by.css('[type="submit"]')).click();
expect(true).toBe(true)
});
});
Also, It would be better to find locators using CSS. Update your question with what error this test will fail.
Protractor is wrapper on selenium, thus when you are plainning to use await/async methods just disable the SELENIUM_PROMISE_MANAGER by setting it as false, so that the protractor promises work well with async/await methods.
I also suggest using pagemodel design pattern which will make the code much readable.
enter code here
export class loginPageObject{
public emailTextBox: ElementFinder;
public passwordTextBox: ElementFinder;
public signInButton: ElementFinder;
public errorMessage: ElementFinder;
constructor(){ //this.emailTextBox = $("input[type='email']");
//this.emailTextBox = element(by.css("body > app-root > div > app-login > div > div > form > div > input"));
this.emailTextBox = $("input[type='email']");
this.passwordTextBox = $("input[type='password']");
this.signInButton = $("button[type='submit']");
this.errorMessage = $("span");
}
}
above is one such sample .. later on you can use it like following way
Can any one help me the set up required to run the Protractor test script in Microsoft edge browser .
I have tried below steps
In the Protractor configuration file
{
'browserName' : 'MicrosoftEdge',
'SharedTestFiles' : false
}
seleniumArgs : ['-Dwebdriver.edge.driver=C:/Windows/SystemApps/Microsoft.MicrosoftEdge_8wekyb3d8bbwe/MicrosoftEdge.exe'],
run the selenium webdriver server with the below command
webdriver-manager start
It is displaying below error message
SessionNotCreatedError: Unable to create new service: EdgeDriverService
I tried below and worked fine for me:-
config.js
exports.config = {
seleniumAddress: 'http://localhost:4444',
capabilities: {
browserName: 'MicrosoftEdge',
elementScrollBehavior: 1,
nativeEvents: false
},
framework: 'jasmine',
baseUrl: 'http://angularjs.org',
specs: [
'spec.js'
],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
}
Test Case/Spec file:-
describe('IE Test cases suite', function() {
it('first IE test case', function() {
browser.get(browser.baseUrl);
browser.getCurrentUrl().then(function(url){
console.log(url);
});
});
});
Also you can find some pre-requisites for webdriver manager refer
https://github.com/angular/protractor/issues/2377#issuecomment-290836086
I am very new to cucumber framework, i started scripting cucumber with protractor, when i try to run the cucumber. conf.js file , I have seen the following error message
[17:07:35] I/launcher - Running 1 instances of WebDriver
[17:07:35] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
UUUUU
Warnings:
1) Scenario: Login with valid userid and password # feature\test.feature:4
? Given I should be at the login page
Undefined. Implement with the following snippet:
Given('I should be at the login page', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? And I provide valid userid and password
Undefined. Implement with the following snippet:
Given('I provide valid userid and password', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? When I click on login button
Undefined. Implement with the following snippet:
When('I click on login button', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? Then I should be able to login inside the Gmail
Undefined. Implement with the following snippet:
Then('I should be able to login inside the Gmail', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
? And The title of web page should be Gmail main page
Undefined. Implement with the following snippet:
Then('The title of web page should be Gmail main page', function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
1 scenario (1 undefined)
5 steps (5 undefined)
0m00.000s
[17:08:31] I/launcher - 0 instance(s) of WebDriver still running
[17:08:31] I/launcher - chrome #01 failed 1 test(s)
[17:08:31] I/launcher - overall: 1 failed spec(s)
[17:08:31] E/launcher - Process exited with error code 1
my conf.js file is
exports.config = {
seleniumAddress : 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
// path relative to the current config file
//frameworkPath: require.resolve('protractor-cucumber-framework'),
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to this directory.
specs: [
'../feature/test.feature',
],
baseURL: 'http://localhost:8080/',
cucumberOpts: {
require: ['../feature/step_definitions/stepDefinitions.js'],
tags: false,
strict: true,
format: ["pretty"],
dryRun: false,
compiler: []
},
onPrepare: function () {
browser.manage().window().maximize();
}
};
if anyone come across this problem, please suggest me how to resolve this.
I'm working on an angular project where we have end to end tests using protractor. We use gulp-protractor to run these tests. Every thing works fine on local. Now we want to increase the number of browsers and devices under tests, so I started to change protractor.conf.js to work with browserstack.
The web application under tests is running locally, so I use browserstack-local as well.
I have a configuration working well for one browser, which test website running on local (inspired from https://github.com/browserstack/protractor-browserstack/blob/master/conf/local.conf.js).
Now, I'm trying to adapt it to run on multi-browsers (following https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel.conf.js). I end up with that configuration:
exports.config = {
framework: 'jasmine2',
onPrepare: common.onPrepare,
// The address of a running selenium server.
seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
commonCapabilities: {
'browserstack.user': 'OUR_USER',
'browserstack.key': 'OUR_KEY',
name: 'Taylor Wimpey e2e tests',
'browserstack.debug': 'true',
'browserName': 'chrome',
'browserstack.local': true
},
multiCapabilities: [{
browserName: 'Chrome'
},{
browserName: 'Safari'
},{
browserName: 'Firefox'
},{
browserName: 'IE'
}],
baseUrl: 'http://localhost:3000',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: [paths.e2e + '/**/*.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
// Code to start browserstack local before start of test
beforeLaunch: function(){
console.log("Connecting local");
return new Promise(function(resolve, reject){
exports.bs_local_args = {
key: exports.config.commonCapabilities['browserstack.key'],
force: true
};
exports.bs_local = new browserstack.Local();
exports.bs_local.start(exports.bs_local_args, function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
onComplete: function(){
console.log('Stop browserstack local');
return new Promise(function(resolve){
exports.bs_local.stop(resolve);
});
}
};
// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) {
caps[i] = caps[i] || exports.config.commonCapabilities[i];
}
});
Tests are launched and worked (my reports are generated for each browsers), but it never stop. Here the end of console logs:
...
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
Connecting local
Connected. Now testing...
[09:05:39] I/launcher - Running 4 instances of WebDriver
......F......FFF^C
so I have to kill them manually, which is not an option as at the end, tests will be running in a continuous integration server.
Does anyone knows how to get e2e tests working on multi-browsers using browserstack with the web application under test running on local?
UPDATE: browserstack support has added an example for multi-capabilities running on local on their github repo: https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel_local.conf.js
The only difference is to use afterLaunch instead of onComplete
Thanks
I am trying to run E2E tests on multiple browsers on browser stack, I took the reference from
E2E testing on multiple/parallel browsers in Protractor?
and
Internet Explorer Selenium protractor e2e tests
but the error I get every time I try to run the tests -
ERROR - Unable to start a WebDriver session.
C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
UnknownError: Authorization required
at new bot.Error (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at Object.bot.response.checkResponse (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:103:11)
But if I run the tests on 1 browser, then it works perfectly fine. this is how my conf file looks like
'use strict';
exports.config = {
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
multicapabilities: [{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost
// 'browserstack.local': 'true',
// Settings for the browser you want to test
'browserName': 'chrome',
'version': '36.0',
'os': 'OS X',
'os_version': 'Mavericks',
'resolution': '1024x768'
},
{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost - 'browserstack.local': 'true',
// Settings for the browser
'browserName': 'firefox',
'os': 'windows'
}],
baseUrl: 'http://origin-develop.mvp.livebranches.com',
// The require statement must be down here, since jasmine-reporters
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
},
};
could anyone please tell me what am I doing wrong here, also we use gulp ti run specs but my problem is it is saying not even going beyond authentication.
I think that first of all, you have an extra comma on your config.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
}, <-----
};