处理casperjs测试中的弹出窗口

时间:2015-10-01 08:13:44

标签: phantomjs casperjs

我正在尝试对可能使用Thirdparties社交登录的登录网页进行测试。例如,当您单击Facebook图标时,会出现一个新的弹出窗口,询问用户/密码。我正在使用文档中指定的waitForPopup和withPopup来处理它,但是无法正常工作。永远不会在xpath中找到元素(通过xpath),因此我无法在测试中使用facebook登录。

这是一个示例代码,用于检查facebook按钮是否存在,单击它并等待弹出窗口:

  casper.then(function() {
    test.comment("When we click facebook button");
    casper.waitForSelector(x(facebookButton),  function() {
      test.assertExists(x(facebookButton), "Facebook icon is showing");
      casper.click(x(facebookButton));
    }, function timeout() { // step to execute if check has failed
      casper.test.fail("Timeout loading login page");
    });
  });

  casper.then(function() {
    casper.waitForPopup(/facebook\.com\/login/,  function() {
      test.comment("And we fill facebook login info");
      casper.withPopup(/facebook\.com\/login/,  function() {
        this.viewport(1600, 900);
        casper.sendKeys(x(facebookEmail), facebookLogin[0]);
        casper.sendKeys(x(facebookPassword), facebookLogin[1]);
        casper.click(x(facebookLogin));
      });
    }, function timeout() { // step to execute if check has failed
      casper.test.fail("Timeout loading faceebook login");
    });
  });

测试的输出是:

# When we click facebook button
PASS Facebook icon is showing
# And we fill facebook login info
FAIL Cannot get informations from xpath selector: //input[@id='email']: element not found.
#    type: uncaughtError
#    file: casper/import-login-testing.js:1058
#    error: Cannot get informations from xpath selector: //input[@id='email']: element not found.
#           CasperError: Cannot get informations from xpath selector: //input[@id='email']: element not found.
#               at getElementInfo (/Users/ginogalotti/testing-presentation/node_modules/casperjs/modules/casper.js:1058)
#               at /Users/ginogalotti/testing-presentation/node_modules/casperjs/modules/casper.js:1589
#               at casper/import-login-testing.js:84
#               at runStep (/Users/ginogalotti/testing-presentation/node_modules/casperjs/modules/casper.js:1553)
#               at checkStep (/Users/ginogalotti/testing-presentation/node_modules/casperjs/modules/casper.js:399)
#    stack: not provided

对我来说,这意味着找到弹出窗口,waitForPopup正在触发,并且只是没有使用弹出窗口来查找facebookEmail元素。我还在学习casperjs,所以这可能不是解决这个问题的最好方法。但我真的要感谢一些指导。

提前致谢,

我正在测试的示例网站:https://import.io/login

0 个答案:

没有答案