FireFox 不会通过 Webdriver JS(通过量角器)切换到非 angular 弹出窗口 window
FireFox doesn't switch to a non-angular popup window by Webdriver JS (via Protractor)
在使用 Jasmine JS 进行的 Selenium Webdriver 测试期间,我无法切换 windows
在 FireFox 浏览器上(最新版本)
亚军:量角器JS
平台:Node.JS
上的 Selenium Webdriver
代码框架:Jasmine JS
代码如下:
describe('LiveSite Portal - Client pay by PayPal', function() {
afterEach(function () {
browser.ignoreSynchronization = false;
});
it('Client LiveSite - Payments - Perform a payment', function () {
var EC = protractor.ExpectedConditions;
browser.get("https://www.vcita.com/v/bungee/home");
var makePayment = element(by.xpath("//div[@class='actions-row']//a[.='Make Payment']"));
browser.wait(EC.visibilityOf(makePayment), 5000);
makePayment.click();
var amount = element(by.name("amount"));
browser.wait(EC.visibilityOf(amount), 5000);
amount.sendKeys("1");
captureScreen("paymentForm");
browser.sleep(3000);
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.sleep(5000);
element(by.xpath("//button[. = 'Continue']")).click();
browser.sleep(2000);
captureScreen("PaymentContinueToPayment");
browser.sleep(3000);
element(by.xpath("//button[. = 'Continue to Payment']")).click();
browser.ignoreSynchronization = true;
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[1]);
var loadLogin = element(by.id("loadLogin"));
browser.wait(EC.visibilityOf(loadLogin), 15000);
loadLogin.click();
});
expect (browser.driver.getCurrentUrl()).toContain('www.paypal.com');
element(by.id("loadLogin")).click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("test2@vcita.com");
element(by.id("login_password")).sendKeys("nhynh2011");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(15000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});
it('Client LiveSite - Payments - Payment Succeed', function () {
expect (browser.driver.getCurrentUrl()).toContain('vcita.com/v/');
captureScreen("PaymentSucceed");
browser.driver.sleep(3000);
element (by.css("a.btn")).click();
browser.driver.sleep(2000);
});
});
有人知道这有什么问题吗?它在 Chrome.
上运行良好
量角器的错误如下:
Failures:
1) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Perform
a payment
Message:
NoSuchElementError: No element found using locator: By.id("loadLogin")
Stacktrace:
NoSuchElementError: No element found using locator: By.id("loadLogin")
at new bot.Error (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\
node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\lib\element.js:
706:15
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\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\np
m\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\promi
se.js:552:16)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
at runMicrotasksCallback (node.js:337:7)
Error
at [object Object].ElementArrayFinder.applyAction_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\lib\element.js:403:21)
at [object Object].self.(anonymous function) [as click] (C:\Users\idan\AppDa
ta\Roaming\npm\node_modules\protractor\lib\element.js:76:19)
at [object Object].self.(anonymous function) [as click] (C:\Users\idan\AppDa
ta\Roaming\npm\node_modules\protractor\lib\element.js:733:11)
at [object Object].<anonymous> (c:\automation\tests\payments.js:48:37)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\ja
sminewd\index.js:94:14
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\
promise.js:1877:20)
at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\
Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdrive
r\promise.js:1755:8)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
From: Task: Asynchronous test function: it()
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\jasminewd\index.js:93:33)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\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:1
7)
at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\no
de_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
at [object Object]._onTimeout (C:\Users\idan\AppData\Roaming\npm\node_module
s\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
at [object Object].<anonymous> (c:\automation\tests\payments.js:8:5)
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\n
ode_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.<anonymous> (c:\automation\tests\payments.js:2:1)
2) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Payment
Succeed
Message:
Expected 'https://www.paypal.com/us/cgi-bin/webscr?dispatch=5885d80a13c0db1
f8e263663d3faee8d99e4111b56ef0eae45e68b8988f5b2dd' to contain 'vcita.com/v/'.
Stacktrace:
Error: Failed expectation
at [object Object].<anonymous> (c:\automation\tests\payments.js:67:49)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\ja
sminewd\index.js:94:14
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\
promise.js:1877:20)
at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\
Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdrive
r\promise.js:1755:8)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
at runMicrotasksCallback (node.js:337:7)
at process._tickCallback (node.js:355:11)
3) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Payment
Succeed
Message:
Error while waiting for Protractor to sync with the page: "angular could no
t be found on the window"
Stacktrace:
undefined
构建您的代码以等待 loadLogin
在单击它之前变得可见。此外,切换到可用句柄列表中的最后一个句柄(Firefox 处理 tabs/windows 不同):
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[handles.length - 1]);
var loadLogin = element(by.id("loadLogin"));
browser.wait(EC.visibilityOf(loadLogin), 15000);
expect(browser.driver.getCurrentUrl()).toContain('www.paypal.com');
loadLogin.click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("test2@vcita.com");
element(by.id("login_password")).sendKeys("nhynh2011");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(15000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});
在使用 Jasmine JS 进行的 Selenium Webdriver 测试期间,我无法切换 windows
在 FireFox 浏览器上(最新版本)
亚军:量角器JS
平台:Node.JS
上的 Selenium Webdriver代码框架:Jasmine JS
代码如下:
describe('LiveSite Portal - Client pay by PayPal', function() {
afterEach(function () {
browser.ignoreSynchronization = false;
});
it('Client LiveSite - Payments - Perform a payment', function () {
var EC = protractor.ExpectedConditions;
browser.get("https://www.vcita.com/v/bungee/home");
var makePayment = element(by.xpath("//div[@class='actions-row']//a[.='Make Payment']"));
browser.wait(EC.visibilityOf(makePayment), 5000);
makePayment.click();
var amount = element(by.name("amount"));
browser.wait(EC.visibilityOf(amount), 5000);
amount.sendKeys("1");
captureScreen("paymentForm");
browser.sleep(3000);
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.sleep(5000);
element(by.xpath("//button[. = 'Continue']")).click();
browser.sleep(2000);
captureScreen("PaymentContinueToPayment");
browser.sleep(3000);
element(by.xpath("//button[. = 'Continue to Payment']")).click();
browser.ignoreSynchronization = true;
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[1]);
var loadLogin = element(by.id("loadLogin"));
browser.wait(EC.visibilityOf(loadLogin), 15000);
loadLogin.click();
});
expect (browser.driver.getCurrentUrl()).toContain('www.paypal.com');
element(by.id("loadLogin")).click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("test2@vcita.com");
element(by.id("login_password")).sendKeys("nhynh2011");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(15000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});
it('Client LiveSite - Payments - Payment Succeed', function () {
expect (browser.driver.getCurrentUrl()).toContain('vcita.com/v/');
captureScreen("PaymentSucceed");
browser.driver.sleep(3000);
element (by.css("a.btn")).click();
browser.driver.sleep(2000);
});
});
有人知道这有什么问题吗?它在 Chrome.
上运行良好量角器的错误如下:
Failures:
1) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Perform
a payment
Message:
NoSuchElementError: No element found using locator: By.id("loadLogin")
Stacktrace:
NoSuchElementError: No element found using locator: By.id("loadLogin")
at new bot.Error (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\
node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\lib\element.js:
706:15
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\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\np
m\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\promi
se.js:552:16)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
at runMicrotasksCallback (node.js:337:7)
Error
at [object Object].ElementArrayFinder.applyAction_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\lib\element.js:403:21)
at [object Object].self.(anonymous function) [as click] (C:\Users\idan\AppDa
ta\Roaming\npm\node_modules\protractor\lib\element.js:76:19)
at [object Object].self.(anonymous function) [as click] (C:\Users\idan\AppDa
ta\Roaming\npm\node_modules\protractor\lib\element.js:733:11)
at [object Object].<anonymous> (c:\automation\tests\payments.js:48:37)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\ja
sminewd\index.js:94:14
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\
promise.js:1877:20)
at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\
Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdrive
r\promise.js:1755:8)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
From: Task: Asynchronous test function: it()
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\jasminewd\index.js:93:33)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\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:1
7)
at [object Object].jasmine.Queue.next_ (C:\Users\idan\AppData\Roaming\npm\no
de_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31)
at [object Object]._onTimeout (C:\Users\idan\AppData\Roaming\npm\node_module
s\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2199:18)
Error
at [object Object].<anonymous> (c:\automation\tests\payments.js:8:5)
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\n
ode_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.<anonymous> (c:\automation\tests\payments.js:2:1)
2) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Payment
Succeed
Message:
Expected 'https://www.paypal.com/us/cgi-bin/webscr?dispatch=5885d80a13c0db1
f8e263663d3faee8d99e4111b56ef0eae45e68b8988f5b2dd' to contain 'vcita.com/v/'.
Stacktrace:
Error: Failed expectation
at [object Object].<anonymous> (c:\automation\tests\payments.js:67:49)
at C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\node_modules\ja
sminewd\index.js:94:14
at [object Object].promise.ControlFlow.runInFrame_ (C:\Users\idan\AppData\Ro
aming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\
promise.js:1877:20)
at [object Object].promise.ControlFlow.runEventLoop_ (C:\Users\idan\AppData\
Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdrive
r\promise.js:1755:8)
at [object Object].<anonymous> (C:\Users\idan\AppData\Roaming\npm\node_modul
es\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at goog.async.run.processWorkQueue (C:\Users\idan\AppData\Roaming\npm\node_m
odules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
at runMicrotasksCallback (node.js:337:7)
at process._tickCallback (node.js:355:11)
3) LiveSite Portal - Client pay by PayPal Client LiveSite - Payments - Payment
Succeed
Message:
Error while waiting for Protractor to sync with the page: "angular could no
t be found on the window"
Stacktrace:
undefined
构建您的代码以等待 loadLogin
在单击它之前变得可见。此外,切换到可用句柄列表中的最后一个句柄(Firefox 处理 tabs/windows 不同):
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[handles.length - 1]);
var loadLogin = element(by.id("loadLogin"));
browser.wait(EC.visibilityOf(loadLogin), 15000);
expect(browser.driver.getCurrentUrl()).toContain('www.paypal.com');
loadLogin.click();
browser.driver.sleep(3000);
element(by.id("login_email")).sendKeys("test2@vcita.com");
element(by.id("login_password")).sendKeys("nhynh2011");
browser.driver.sleep(1000);
element(by.id("submitLogin")).click();
browser.driver.sleep(10000);
element(by.id("submit.x")).click();
browser.driver.sleep(15000);
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[0]);
});
});