Timeout issue in protractor - protractor

My test case has executed successfully from the UI perspective, but still getting the error as below instead of saying giving the result as Passed.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Could you please let me know what the reason may be.
My conf file is as below:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['DMSE2E1.js'],
framework: 'jasmine2',
jasmineNodeOpts: { defaultTimeoutInterval: 40000 }
}

May be your scenario step is waiting to be notified for completing all lines in a scenario.
When using async/await
it('Some test', async () => {
await expect(homepg.getdata()).to.eventually.be.true
});
When using callbacks
it('some text',(callback) => {
expect(homepg.getdata()).to.eventually.be.true.and.notify(callback);
});

Related

How to perform beforeTest and afterTest method using typescript (protractor+cucumber)

Framework used - Protractor
BDD - Cucumber
Language - Typescript
Now i have implemented the framework and a test scenario is also running fine with protractor.
But the problem i am facing is when i write another cucumber scenario my test fails saying 'A session is either terminated or not started'
The above failure is because when my first cucumber scenario starts the appium server starts with in my config and at the end i close the server/driver
Now i have written another test scenario, since cucumber is independent of each scenario , when the sec starts it does not do the config again. Now i need a beforeTest method to call.
So i am not sure how to implement that in typescript,as i am new to it.
Tried the same concept of java way but not working out. There where examples for javascript but still did not help me out.
Tried creating a new util folder and placing my beforeTest inside that but the function is not calling there
Tried to use beforeLaunch()with in my config file, but still does not work out
my config file: config.ts
export let config: Config = {
allScriptsTimeout: 40000,
getPageTimeout: 40000,
setDefaultTimeout: 60000,
defaultTimeoutInterval: 30000,
specs: [
// '../../utils/beforeEach.ts',
'../../features/*.feature',
],
onPrepare: () => {
Reporter.createDirectory(jsonReports);
tsNode.register({
project: './tsconfig.json'
});
},
multiCapabilities: [
androidPixel2XLCapability,
// iPhoneXCapability
],
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
compiler: "ts:ts-node/register",
glue: ["steps"],
format: [
"json:./reports/json/cucumber_report.json",
],
require: ['supports/timeout.js', '../../stepdefinitions/*.ts'],
tags: "#firstPurchasePopup",
},
seleniumAddress: serverAddress,
onComplete: () => {
Reporter.createHTMLReport();
},
// =====
// Hooks
// =====
beforeTest: function () {
},
beforeLaunch(){
console.log("Before");
seleniumAddress: 'http://localhost:4723/wd/hub';
},
afterLaunch() {
console.log("After");
},
};
my other beforeEach.ts:
This is not working but what i tired and was not working.
import {After, AfterAll, Before} from "cucumber";
const serverAddress = 'http://localhost:4723/wd/hub';
import {beforeEach, afterEach, describe} from "selenium-webdriver/testing";
beforeEach(function () {
console.log("Before");
});
// });
afterEach(function () {
console.log("Before");
});
// let beforeEach: () => void;
// beforeEach = () => {
// console.log("Before Test");
// // config.multiCapabilities;
// seleniumAddress: serverAddress;
// };
//
// let afterEach: () => void;
// afterEach = () => {
// console.log("After Test");
// };
This is my feature file: bonus.feature
this is my feature file:
Background:
Given I launch the app
Then I should see the popup window for the Bonus
And I verify the UI
Then I tap on ok button
And The popup window should not be seen
#firstPurchasePopup
Scenario: firstPurchasePopup new join button
When I tap on the 'New ' button
And The popup window should not be seen
Then I navigate back from join page to home page
Then The popup window should not be seen
Then I close the app
#firstPurchasePopup
Scenario: firstPurchasePopup login button
And I tap on log in button on the initial screen
Then I navigate back from login page to home page
And The popup window should not be seen
Then I close the app
I expect my the scenario what i have written to execute both one after the other , like execute Scenario: firstPurchasePopup new join button which it does . But when it launches the app again for the sec Scenario: firstPurchasePopup login button does not work as the driver is not started again, since it was closed in prev one.
to start it i need to create beforeTest which i am facing difficutly to write the code
I haven't used Protractor with Cucumber, but I have used Cucumber & Typescript together. I resolved the problem by having a file cucumber.js in a root that is being loaded at the very beginning by default and looks like that:
var settings = "features/**/*.feature -r step-definitions/**/*.ts -r hooks/**/*.ts -r support/**/*.ts "
module.exports = {
"default": settings
}
However, I think in your case the solution would be adding a path to hooks file to config.cucumberOpts.require list instead to config.specs one.
Did you try it?
#All
Thanks for your inputs #mhyphenated
I figured out that the rather than using inside the config, i tried using the before and after in the hooks.ts ,also other than calling the server i was not actually calling the android driver, as below and that worked
beforeTest: function () {
beforeTest: function () {
},
beforeLaunch(){
console.log("Before");
seleniumAddress: 'http://localhost:4723/wd/hub';
},
hooks.ts
import { AndroidDriver } from "appium/node_modules/appium-android-driver";
let driver:AndroidDriver, defaultCaps;
driver = new AndroidDriver();
Before(function () {
// This hook will be executed before all scenarios
browser.ignoreSynchronization = false;
browser.manage().timeouts().implicitlyWait(500);
let defaultCaps = config.multiCapabilities[0];
console.log("defaultCaps = ", defaultCaps );
driver.createSession(defaultCaps);
driver.defaultWebviewName();
});

Protractor : not able to find element in login page

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

ScriptTimeoutError: Timed out - From: Task: Protractor.waitForAngular()

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.

Timed out waiting for Protractor to synchronize with the page after 11 seconds

I am new to Protractor and have been trying to run end to end test. I have tried other respondent but still i am getting the above error
My protractor conf.js looks like this:
directConnect: true,
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 2500000,
getPageTimeout: 30000,
print: function() {}
},
spec.js looks like this
describe('b2-bportral standardOrder', function () {
let onlineOrderPage: OnlineOrderPage;
let loginPage: LoginPage
beforeEach(() => {
browser.driver.manage().window().maximize();;
loginPage = new LoginPage();
loginPage.navigateTo();
loginPage.setUserName("canon#gmail.com");
loginPage.setPassword("a");
loginPage.loginClick();
onlineOrderPage = new OnlineOrderPage();
onlineOrderPage.navigateTo();
browser.waitForAngular();
});
it('Standard Order', () => {
onlineOrderPage.setPartnerName("");
});
});
po.ts looks like this :
export class LoginPage {
navigateTo() {
return browser.get('#/login',30000);
}
setUserName(username:string) {
element(by.id("username")).sendKeys(username);
}
setPassword(password:string) {
element(by.id("password")).sendKeys(password);
}
loginClick(){
return element(by.className("login")).click();
}
}
export class OnlineOrderPage {
navigateTo() {
browser.get('url',30000);
}
setPartnerName(value:string){
element(by.id('selPartnerName')).click();
return element(by.cssContainingText('option', 'CANON MIDLE EAST')).click();
}
}
Error:
b2-bportral standardOrder
× Standard Order
- Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
- Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md
While waiting for element with locator - Locator: By(css selector, *[id="selPartnerName"])
Anyone please guide me
Protractor tries to load your page, but it timeouts before it can fully load it. There are two possiblities. First make sure you specified correct URL for your page and that your page actually starts to load before timeouting.
Secondly you can increase the timeout for loading page (default is 10) in two ways:
In your configuration file set getPageTimeout: 30000 to increase
timeout for every browser.get()
Specify timeout for each individual function with parameter, for
example: browser.get("url", 30000); Note that browser.driver.get() uses only 1 parameter, so be sure to use browser.get().
Also if above solutions don't work for you, you may want to try setting timeout for webdriver. You can set it in configuration file with this line: allScriptsTimeout: 30000
All values are in milliseconds
EDIT:
First of all put browser.pause() and when it pauses look at the browser and see if element with id selPartnerName really exists.
If it exists try waiting for it longer with this code:
var el = element(by.id('selPartnerName'));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(el), 30000);

Protractor ,Jasmine timeout issue

I'm doing e2e-testing with Protractor and Jasmine. Our application is in Angular.
I have written given getPageTimeout: 500000, allScriptsTimeout: 600000, in the config file. Added defaultTimeoutInterval:500000 as per GitHub .
Even then I'm getting the below exception. Appreciate any help.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
Protractor.waitForAngular()
at [object Object].webdriver.WebDriver.schedule (C:\Users\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:345:15)
at [object Object].Protractor.executeAsyncScript_ (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\protractor.js:1141:26)
at [object Object].Protractor.waitForAngular (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\protractor.js:1159:15)
at [object Object].getWebElements (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\protractor.js:191:21)
at [object Object].getWebElements
Angular is never becoming ready in your app. The only reason why you're seeing jasmine timeout instead of protractor timeouts is because you increased your protractor timeout limit to be higher than your jasmine timeout limit. This is likely a problem with the app polling indefinitely, rather than a problem with how you're writing your test.
From https://github.com/angular/protractor/blob/master/docs/timeouts.md:
"Before performing any action, Protractor asks Angular to wait until the page is synchronized. This means that all timeouts and http requests are finished. If your application continuously polls $timeout or $http, it will never be registered as completely loaded. You should use the $interval service (interval.js) for anything that polls continuously (introduced in Angular 1.2rc3)."
For people running in this issue only when using Internet Explorer as test browser try to force a new clean session every test:
protractor-conf.js
{"browserName": "internet explorer",
"ie.forceCreateProcessApi": true,
"ie.browserCommandLineSwitches": "-private",
"ie.ensureCleanSession": "true",
"seleniumAddress": 'http://10.0.1.XXX:4444/wd/hub'
}
Ensure that TabProcGrowth" = dword: 00000000 in Path HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main is set.
Set in your config file eg:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
suites: require('./Suites.js'),
capabilities: {
browserName: 'chrome'
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 360000
},
allScriptsTimeout: 360000,
};
Try this:
describe('Something', function()
{
it('should do something', function() {
},500000);
},500000);
Try adding below timeoutinterval in config file
jasmineNodeOpts: {
defaultTimeoutInterval: 360000
}
Try adding below code, jasmine default time 5 sec. The below code will wait for all test cases to complete it task & working fine for me.
jasmine.getEnv().defaultTimeoutInterval =15000;
onPrepare: function(){
jasmine.getEnv().defaultTimeoutInterval =your time to set in milli second;
}
For Angular2+ a quick answer here to shorten your research.
Instead of things like setInterval(() => {}, 20000); just use this:
this.ngZone.runOutsideAngular(() => {
setInterval(() => {
this.ngZone.run(() => {
// whatever you want to do from time to time
});
}, 20000);
});
you can add ngZone as any other service in constructor, like this:
private ngZone: NgZone,
Make sure you have reviewed all component's chain starting from app-root (AppComponent.ts) and also including custom services. Timer that been set anywhere can cause this issues.