【问题标题】:e2e ionic2 test code does not worke2e ionic2 测试代码不起作用
【发布时间】:2016-05-03 12:25:51
【问题描述】:

我正在尝试使用量角器为我的应用程序编写 e2e 这是我的应用程序的登录页面

<ion-navbar *navbar primary>
    <ion-title>{{config.organization}} - Login</ion-title>
</ion-navbar>

<ion-content>
    <ion-list>

        <form #loginForm="ngForm" novalidate>
            <ion-item>
                <ion-label floating primary>Username</ion-label>
                <ion-input [(ngModel)]="userProvider.userName" (change)='onUserNameChange()' ngControl="username" type="text" #username="ngForm" id='userNameField' required>
                </ion-input>
            </ion-item>
            <p [hidden]="username.valid || submitted == false" danger padding-left>
                Username is required
            </p>

            <ion-item>
                <ion-label floating primary>Password</ion-label>
                <ion-input [(ngModel)]="userProvider.password" (change)='onPasswordChange()' ngControl="password" type="password" #password="ngForm" id='passwordField' required>
                </ion-input>
            </ion-item>
            <p [hidden]="password.valid || submitted == false" danger padding-left>
                Password is required
            </p>

            <ion-row responsive-sm >
                <button  (click)="onLogin(loginForm)" id="logInButton" type="submit" primary round>Login</button>
            </ion-row>

            <ion-item>
                Server: {{ob3URL}}
            </ion-item>


            <ion-row [hidden]='!wrongCredential'>
                <p danger class='errorElement'>
                    Username / Password is wrong
                </p>
            </ion-row>

        </form>

    </ion-list>

</ion-content>

在我的规范文件中我使用了这个

it('should start with empty fields',() => {
        expect((element.all(by.css('.text-input')).get(0)).toContain(""))
    });

要检查天气页面是否有页面加载数据,但是当我执行此操作时,我的终端出现错误 app/pages/login/login.e2e.ts (21,60):“ElementFinder”类型上不存在属性“toContain”。 (2339)

如果我发送密钥,它会在该文本框中发送密钥,但我无法使用 toBe(""),toContain('') 检查它 有人可以帮我吗

【问题讨论】:

    标签: angular protractor ionic2


    【解决方案1】:

    类型“ElementFinder”上不存在属性“toContain”。

    这里有几个问题:

    • 您混淆了引号。 toContain() 需要在 expect() 的结果上调用
    • 由于需要检查输入字段是否为空,所以需要在输入的value属性上使用toEqual("")
    • 我在您发布的 HTML 中没有看到带有 text-input 类的元素,但我假设您知道此时您所在的位置

    固定版本:

    expect(element.all(by.css('.text-input')).get(0).getAttribute("value")).toEqual("");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-10
      • 2018-02-18
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2022-07-08
      相关资源
      最近更新 更多