【问题标题】:Detox - Tap a button when it becomes enabled排毒 - 启用时点击一个按钮
【发布时间】:2018-06-26 18:01:10
【问题描述】:

在使用 Detox 进行测试时,我在按钮上执行 tap() 时遇到问题。

<Button style={this._loginButtonDisabled() ? {} : styles.loginButtonActive}
        disabled={this._loginButtonDisabled()}
        onPress={this.logInClick}
        testID='logInButton'>
    <Text style={styles.loginButtonText}>Log In</Text>
</Button>   

我们的测试如下所示:

const emailInput = element(by.id('emailInput'));
await emailInput.replaceText('idontexist@myeatclub.com');

const passwordInput = element(by.id('passwordInput'));
await passwordInput.replaceText('password');

await element(by.id('logInButton')).tap();

按钮始终可见,但只有在表单字段中输入文本后才会启用(“可点击”)。因此,上面的代码在启用之前点击了按钮,导致没有实际操作。我想做的是等到按钮启用,然后执行点击。

处理这种情况的建议方法是什么?我在文档中找不到任何好的示例。

【问题讨论】:

    标签: testing react-native detox


    【解决方案1】:

    我认为这是因为您使用的是 replaceText

    改为尝试使用 typeText

    像这样:

    const emailInput = element(by.id('emailInput'));
    await emailInput.replaceText('idontexist@myeatclub.com');
    
    const passwordInput = element(by.id('passwordInput'));
    // \n is used to press the return key on keyboard
    await passwordInput.typeText('password\n');
    
    await element(by.id('logInButton')).tap();
    

    【讨论】:

    • 谢谢,是的,它似乎工作!但另一方面,模拟器长时间(在任何时候使用 CMD+H)似乎会导致打开软件键盘出现问题,然后 typeText() 只是反复失败。我之前遇到过这个问题,这就是我最初使用 replaceText 的原因。
    猜你喜欢
    • 2018-03-14
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 2012-06-21
    • 2018-05-03
    相关资源
    最近更新 更多