【问题标题】:Issues with using phantomJs and protractor使用 phantomJs 和量角器的问题
【发布时间】:2014-08-17 08:42:00
【问题描述】:

我正在使用量角器和 PhantomJs 对我的 Angular 应用程序进行 e2e 测试。

目前我正在测试登录表单。当我只是检查时,所有测试都可以正常工作

  1. 表单是否加载正确
  2. 用户名/密码字段为空
  3. 输入错误的身份验证信息时会显示错误。

到目前为止,phantomJs 和量角器一直很合作

但是,下面提到的测试用例在量角器中总是失败。我尝试了各种排列组合,但无济于事。

当用户在登录表单中输入正确的身份验证信息时,Angular 应用程序将更改路由到仪表板部分。即浏览器窗口中的 url 将从

http://localhost:12345/#/signin/
to 
http://localhost:12345/#/dashboard

当我运行以下给测试时,我知道身份验证成功,因为服务器日志显示发送的成功响应对象。收到此响应后,角度应用程序应该已将路由更改为 /dashboard。但是量角器无法捕捉到这种路线变化。

我的测试如下所示:

describe("SignOn Page - Performing authentication with valid credentials ",function(){
  var ptor;

  beforeEach(function(){
    ptor = protractor.getInstance();
    ptor.get('#/signon');
    ptor.findElement(protractor.By.id('username')).sendKeys('joe');
    ptor.findElement(protractor.By.id('password')).sendKeys('pass');
    element(by.partialButtonText('Sign In')).click();
    ptor.waitForAngular();
  });

  it("should re-direct user to dashboard page once the user enters correct authentication information",function(){
    ptor = protractor.getInstance();
    expect(ptor.getCurrentUrl()).toContain('dashboard');
    expect(ptor.getTitle()).toContain('dashboard');
  });


});

我对这个论坛的问题是,量角器在改变状态时有问题吗?我在我的 Angular 应用程序中使用 ui.router 吗?

【问题讨论】:

  • 你试过 Chrome 或 Firefox 吗?我已经在 http 请求中遇到了 phantomjs 特有的问题
  • 是的.. chrome 驱动程序运行良好.. 暂时放弃了 phatomjs
  • 我是这么想的,您可以浏览the 1200+ phantomjs opened issues 来查找是否符合您的情况://祝您好运!
  • 已经这样做了..我看到了相关问题但没有解决方案,因此我在这个论坛上提出了问题..
  • 我在使用 ngRouter 而不是 ui.router 时遇到了同样的问题。你找到解决办法了吗?

标签: angularjs phantomjs protractor


【解决方案1】:

我遇到了同样的问题,因为我使用的是 phantomJS 1.9.x 而不是 2.x

所以你需要卸载 phantomjs 1.9

npm remove -g phantomjs

并安装 phantomJS 2.x

npm install -g phantomjs2

希望它也能解决您的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多