Despite my efforts to ensure the stability of my test, there are instances where it does not wait for all elements within an integrated popup, resulting in failure.
This particular test case is quite intricate as it involves nested if statements to execute relevant code for both FireFox and Chrome (as they handle popup windows differently).
Furthermore, there is a secondary condition where the test should not click on the element with id="loadLogin" if the user is already logged in.
The CSS styling of the tested element:
<input type="submit" value="Log in to your PayPal account" id="loadLogin" name="login_button" class="parentSubmit">
Test case - code:
it('Existing Client LiveSite - Payments - Continue To Payment', function () {
element(by.binding("client_zone.payous.new.continue")).click();
waitPageToLoad();
});
it('Existing Client LiveSite - Payments - Perform a payment by PayPal', function () {
var loadLogin = element(by.id("loadLogin"));
browser.wait(EC.visibilityOf(element(by.binding("buttonText"))), 15000);
element(by.binding("buttonText")).click();
if (browser === 'firefox') {
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[handles.length - 1]);
element.all(by.id('loadLogin')).then(function(){
// expect(browser.driver.getCurrentUrl()).toContain('www.paypal.com');
if (loadLogin) {
loadLogin.click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("username");
element(by.id("login_password")).sendKeys("password");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(5000);
element(by.id("submit.x")).click();
browser.driver.sleep(10000);
console.log("-=-=- first condition - FF -=-=-");
} else {
element(by.id("login_email")).clear();
browser.driver.sleep(1000);
element(by.id("login_email")).sendKeys("username");
element(by.id("login_password")).sendKeys("password");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(10000);
console.log("-=-=- second condition - FF -=-=-")
}
});
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});
}
else {
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[1]);
element.all(by.id('loadLogin')).then(function(){
// expect(browser.driver.getCurrentUrl()).toContain('www.paypal.com');
if (loadLogin) {
loadLogin.click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("username");
element(by.id("login_password")).sendKeys("password");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(5000);
element(by.id("submit.x")).click();
browser.driver.sleep(10000);
console.log("-=-=- first condition - Chrome -=-=-");
} else {
element(by.id("login_email")).clear();
browser.driver.sleep(1000);
element(by.id("login_email")).sendKeys("username");
element(by.id("login_password")).sendKeys("password");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(10000);
console.log("-=-=- second condition - Chrome -=-=-")
}
});
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});
};
});
Error:
c:\automation\tests>protractor conf.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instance(s) of WebDriver
imapConnected
LiveSite Portal - Existing client pay by PayPal
LiveSite - Home Page - pass
Existing Client LiveSite - Payments - Payment form - pass
LiveSite Portal - Existing client payments - Welcome note for existing client
- pass
Existing Client LiveSite - Payments - Continue To Payment - pass
-=-=- first condition - Chrome -=-=-
Existing Client LiveSite - Payments - Perform a payment by PayPal - fail
Failures:
1) LiveSite Portal - Existing client pay by PayPal Existing Client LiveSite -
Payments - Perform a payment by PayPal
Message:
ElementNotVisibleError: element not visible
(Session info: chrome=43.0.2357.130)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.3 x86_64)...
...