I can't switch windows during my testing by Selenium Webdriver using Jasmine JS.
Runner: Protractor JS
Platform: Selenium Webdriver on Node.JS
Code framework: Jasmine JS
The code is below, Please note the second code block:
describe('payments', function() {
// beforeEach(function() {
// browser.ignoreSynchronization = true;
// });
// afterEach(function(){
// browser.ignoreSynchronization = false;
// });
this.selectWindow = function (index) {
browser.driver.wait(function() {
return browser.driver.getAllWindowHandles().then(function (handles) {
if(handles.length > index) {
return true;
}
});
});
return browser.driver.getAllWindowHandles().then(function (handles) {
return browser.driver.switchTo().window(handles[index]);
});
};
it('Client LiveSite - Payments - Perform a payment', function() {
browser.driver.get("https://www.vcita.com/v/bungee/home");
browser.driver.sleep(5000);
element(by.xpath("//div[@class='actions-row']//a[.='Make Payment']")).click();
browser.driver.sleep(2000);
element(by.name("amount")).sendKeys("5");
// element(by.model("payou_request.payou.amount")).sendKeys("5");
element(by.name("pay_for")).sendKeys("Mister Bungee");
element(by.name("notes")).sendKeys("Please approve my payments. Thanks a lot, Dr. Kugler. +972545453435");
element(by.name("email")).sendKeys("idanvcita@gmail.com");
element(by.name("first_name")).click();
browser.driver.sleep(5000);
element(by.css("button.btn.ng-binding")).click();
});
it('paypal', function() {
browser.ignoreSynchronization = false;
browser.driver.getAllWindowHandles().then(function (handles) {
browser.driver.switchTo().window(handles[1]);
});
element(by.id("pay_button")).click();
browser.driver.sleep(10000);
// it('Client LiveSite - Payments - PayPal Lightbox', function() {
// handlePromise.then(function (handles) {
// var popUpHandle = handles[1];
// var handle = driver.switchTo().window(popUpHandle).getWindowHandle();
// expect (handle).toEqual(popUpHandle);
// });
//expect (element(by.text("Your payment summary")).isPresent()).toBe(true);
element(by.id("loadLogin")).click();
browser.driver.sleep(1000);
element(by.id("login_email")).sendKeys("email");
element(by.id("login_password")).sendKeys("pass");
element(by.id("submitLogin")).click();
element(by.id("login_password")).click();
element(by.id("submit.x")).click();
});
});
The error from Node.JS:
UnknownError: null value in entry: name=null at new bot.Error (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18) at Object.bot.response.checkResponse (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:106:9) at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:377:20 at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) at [object Object].promise.Promise.notify_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) at Array.forEach (native) at Object.goog.array.forEach (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) at [object Object].promise.Promise.notifyAll_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16) at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) From: Task: Asynchronous test function: it() at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33) at [object Object]. (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37) at [object Object].jasmine.Block.execute (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17) at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at [object Object].jasmine.Queue.start (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2162:8) at [object Object].jasmine.Spec.execute (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2503:14) at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at onComplete (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2205:18) at [object Object].jasmine.Spec.finish (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2477:5) at [object Object].onComplete (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2504:10)==== async task ==== Error at [object Object]. (c:\automation\tests\payments.js:44:3) at [object Object].jasmine.Env.describe_ (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21) at [object Object].jasmine.Env.describe (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15) at describe (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27) at Object. (c:\automation\tests\payments.js:2:1) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12)
This is the relevant css code:
<title>Pay with a PayPal account - PayPal</title><meta name="description" content="PayPal is the safer, easier way to pay online without revealing your credit card number."><meta http-equiv="X-UA-Compatible" content="IE=9"><link media="screen" rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-640-20150318-1/css/core/global.css"><link rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-640-20150318-1/Merchant/css/AP/checkout.css">