使用量角器在非角度站点上使用预期条件导致“类型错误:无法读取未定义的属性‘绑定’" [英] Use of Expected Conditions on Non Angular Site with Protractor Leads to "Type Error: Cannot read property 'bind' of undefined"

查看:49
本文介绍了使用量角器在非角度站点上使用预期条件导致“类型错误:无法读取未定义的属性‘绑定’"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在通过量角器的元素对象返回的 webelement 上使用预期条件时,我看到以下问题.我也试过 $ ,结果是一样的.我在 Node 4.2.4、Chrome V47 上使用 Protractor 3.1.1.*

I am seeing following issue when I am using Expected Conditions on webelements returned through element object of Protractor. I tried with $ as well, that resulted in the same thing. I am using Protractor 3.1.1 on Node 4.2.4, Chrome V47.*

类型错误:无法读取未定义的属性‘绑定’"

在提问之前,我搜索了论坛,并了解到使用 driver.findElement 对硒元素使用预期条件存在一些已知问题.

Before asking, I searched the forums, and understood there are some known issues with using Expected Conditions with selenium elements using driver.findElement.

但是,我在使用元素对象本身时没有遇到类似的问题.

However, I could not come across a similar issues reported while using element object itself.

https://github.com/angular/protractor/issues/1853

我们有一个用于登录页面的非 Angular 应用程序,它将在登录后切换到 Angular.所以,我设置了 ignoreSynchronization=true ,后来计划在登录后将其重置为 false.以下是示例代码,感谢社区的任何想法.

We have a non angular app for login page, which will be switched to Angular, post login. So, I have set ignoreSynchronization=true and later planned to reset it to false after login. Below is the sample code, appreciate any thoughts from community.

页面对象文件

module.exports = {
    login: element(by.model('credentials.username')),
    password: element(by.model('credentials.password')),
    user: "Email",
    passwd: "Password",
    goButton: $('input.btn.btn-primary'),
    EC: protractor.ExpectedConditions,
    go: function() {

    browser.get("Application URL",30000);
    browser.wait(this.EC.elementToBeClickable(this.login),30000);
    },

下面是我的示例测试套件

var VMPage = require('./LoginPage.js');


   describe('App Demo', function() {
    beforeEach(function() {
    console.log("Before Each Started");
    browser.driver.manage().timeouts().implicitlyWait(30000);
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 1800000;
    browser.ignoreSynchronization = true;
    VMPage.go();
    VMPage.login();
    });

    it('Test Case', function() {
       console.log("***Test Started***");

    });

});

报告的堆栈跟踪如下所示:堆栈:

    TypeError: Cannot read property 'bind' of undefined
        at [object Object].ExpectedConditions.presenceOf (C:\Users\PJ\Ap
pData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:289:33)
        at [object Object].ExpectedConditions.visibilityOf (C:\Users\PJ\
AppData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:328:10)
        at [object Object].ExpectedConditions.elementToBeClickable (C:\Users\PJ0
0366401\AppData\Roaming\npm\node_modules\protractor\lib\expectedConditions.js:17
8:12)
        at Object.module.exports.go (D:\protractor_git\Demo\\Log
inPage.js:14:24)
        at Object.<anonymous> (D:\protractor_git\Demo\\LoginTest
.js:9:10)
        at C:\Users\PJ\AppData\Roaming\npm\node_modules\protractor\node_
modules\jasminewd2\index.js:96:23
        at new wrappedCtr (C:\Users\PJ\AppData\Roaming\npm\node_modules\
protractor\node_modules\selenium-webdriver\lib\goog\base.js:2468:26)
        at controlFlowExecute (C:\Users\PJ\AppData\Roaming\npm\node_modu
les\protractor\node_modules\jasminewd2\index.js:82:18)
    From: Task: Run beforeEach in control flow
        at Object.<anonymous> (C:\Users\PJ\AppData\Roaming\npm\node_modu
les\protractor\node_modules\jasminewd2\index.js:81:14)
        at attemptAsync (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:1916:24)
        at QueueRunner.run (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:1871:9)
        at QueueRunner.execute (C:\Users\PJ\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\
jasmine.js:1859:10)
        at Spec.Env.queueRunnerFactory (C:\Users\PJ\AppData\Roaming\npm\
node_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmi
ne-core\jasmine.js:697:35)
        at Spec.execute (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:359:10)
        at Object.fn (C:\Users\PJ\AppData\Roaming\npm\node_modules\protr
actor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine.js
:2479:37)
        at attemptAsync (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:1916:24)
        at QueueRunner.run (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:1871:9)
        at QueueRunner.execute (C:\Users\PJ\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\
jasmine.js:1859:10)
    From asynchronous test:
    Error
        at Suite.<anonymous> (D:\protractor_git\Demo\\LoginTest.
js:3:2)
        at addSpecsToSuite (C:\Users\PJ\AppData\Roaming\npm\node_modules
\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasm
ine.js:833:25)
        at Env.describe (C:\Users\PJ\AppData\Roaming\npm\node_modules\pr
otractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine
.js:802:7)
        at jasmineInterface.describe (C:\Users\PJ\AppData\Roaming\npm\no
de_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine
-core\jasmine.js:3375:18)
        at Object.<anonymous> (D:\protractor_git\Demo\\LoginTest
.js:2:1)

推荐答案

你的 页面对象应该定义为一个函数:

Your page object should be defined as a function:

var Page = function () {
    this.login = element(by.model('credentials.username'));
    this.password = element(by.model('credentials.password'));
    this.user = "Email";
    this.passwd = "Password";
    this.goButton = $('input.btn.btn-primary');

    this.EC = protractor.ExpectedConditions;

    this.go = function() {
        browser.get("Application URL", 30000);
        browser.wait(this.EC.elementToBeClickable(this.login), 30000);
    };
};

module.exports = new Page();

这篇关于使用量角器在非角度站点上使用预期条件导致“类型错误:无法读取未定义的属性‘绑定’"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆