简体   繁体   English

量角器-打开弹出窗口时,它不等待该窗口内的所有元素

[英]Protractor - When opening a popup it doesn't wait for all elements inside this window

I've tried to make my test to be stable, but sometimes it's not wait for all elements inside an integrated popup and it's failed. 我试图使我的测试稳定,但是有时候它并没有等待集成弹出窗口中的所有元素,但是它失败了。

This test case is little bit complex because it including if statement inside another if statement in order to run the relevant code for FireFox and for Chrome as well (they have different handling with popup windows), 这个测试用例有点复杂,因为它在另一个if语句中包含了if语句,以便同时为FireFox和Chrome运行相关的代码(它们对弹出窗口的处理方式不同),

also the second condition is for case that the user is already logged-in and it should not click on the element of id="loadlogin". 同样,第二个条件是用户已经登录并且不应该单击id =“ loadlogin”元素的情况。

The CSS of the tested element: 被测元素的CSS:

<input type="submit" value="Log in to your PayPal account" id="loadLogin" name="login_button" class="parentSubmit">

Test case - code: 测试用例-代码:

 it('Exisiting Client LiveSite - Payments - Continue To Payment', function () {
    element(by.binding("client_zone.payous.new.continue")).click();
    waitPageToLoad();
});

it('Exisiting 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 instances of WebDriver
imapConnected
LiveSite Portal - Existing client pay by PayPal
  LiveSite - Home Page - pass
  Exisiting Client LiveSite - Payments - Payment form - pass
  LiveSite Portal - Exisiting client payments - Welcome note for existing client
 - pass
  Exisiting Client LiveSite - Payments - Continue To Payment - pass
-=-=- first condition - Chrome -=-=-
  Exisiting Client LiveSite - Payments - Perform a payment by PayPal - fail


Failures:

  1) LiveSite Portal - Existing client pay by PayPal Exisiting 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 (3d645c400edf2e2c500566c9aa096063e707c9
cf),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any sta
cktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'vCitaQA', ip: '192.168.152.1', os.name: 'Windows 8.1', os.ar
ch: 'amd64', os.version: '6.3', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEn
abled=false, chrome={userDataDir=C:\Users\idan\AppData\Local\Temp\scoped_dir7328
_2982}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, versi
on=43.0.2357.130, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=
true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true,
browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEn
abled=true}]
Session ID: 64d27a4f28d3db93bbb59b8184c87a07
   Stacktrace:
     ElementNotVisibleError: element not visible
  (Session info: chrome=43.0.2357.130)
  (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9
cf),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any sta
cktrace information)
Command duration or timeout: 23 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'vCitaQA', ip: '192.168.152.1', os.name: 'Windows 8.1', os.ar
ch: 'amd64', os.version: '6.3', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEn
abled=false, chrome={userDataDir=C:\Users\idan\AppData\Local\Temp\scoped_dir7328
_2982}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, versi
on=43.0.2357.130, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=
true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true,
browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEn
abled=true}]
Session ID: 64d27a4f28d3db93bbb59b8184c87a07
    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\se
lenium-webdriver\lib\webdriver\webdriver.js:377:20
    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)
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 c:\automation\tests\payments.js:94:35
    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)
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 onComplete (C:\Users\idan\AppData\Roaming\npm\node_modules\protractor\nod
e_modules\minijasminenode\lib\jasmine-1.3.1.js:2205:18)
    at [object Object].jasmine.WaitsForBlock.execute (C:\Users\idan\AppData\Roam
ing\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.j
s:2704:5)
    at [object Object]._onTimeout (C:\Users\idan\AppData\Roaming\npm\node_module
s\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2718:12)
Error
    at [object Object].<anonymous> (c:\automation\tests\payments.js:43: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:1:63)

Finished in 19.473 seconds
5 tests, 3 assertions, 1 failure

[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

c:\automation\tests>  element.all(by.id('loadLogin')).then(function(){
'element.all' is not recognized as an internal or external command,
operable program or batch file.

c:\automation\tests>

I think the problem could be is that you are not switching to the right window because the order of windows could be dynamic. 我认为问题可能是您没有切换到正确的窗口,因为窗口的顺序可能是动态的。 This is what I would suggest, 这就是我的建议

  1. Before clicking on the loadLogin button I would save the main window handle. 在单击loadLogin按钮之前,我将保存主窗口句柄。 After all window handles are nothing but an array of hash 毕竟窗口句柄不过是哈希数组
  2. When you click on the login, just switch to the window that is NOT main window. 当您单击登录名时,只需切换到非主窗口即可。 This way you can perform login without having to blindly switching to a window. 这样,您无需盲目切换到窗口即可执行登录。 I think this will also simplify your firefox vs chrome logic 我认为这也将简化您的Firefox与Chrome逻辑

So something like this pseudo code, 所以像这样的伪代码,

var mainWindow;
browser.getAllWindowHandles().then(
    function(handles) {
        mainWindow = handles[0]; //at this point there should be only 1 window
    }
);

browser.getAllWindowHandles().then(function (handles) {      
   handles.forEach(function(handle) {
     if (handle !== mainWindow) {
        browser.switchTo().window(handle);
        element.all(by.id('loadLogin')).then(function(){ 
            //do more stuff
        }
     }
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM