【问题标题】:Testing the tooltip / customValidity message with Codeception/Selenium?使用 Codeception/Selenium 测试工具提示/customValidity 消息?
【发布时间】:2019-01-02 08:07:03
【问题描述】:

在我的 Codeception 场景中,我想检查当我提交带有一些用户错误的表单(例如确认错误的电子邮件)时,浏览器会显示带有我的自定义消息的工具提示。

HTML

<form ... >
    <label>Email *</label>
    <p>
    <input type="email" name="email" id="email placeholder="Please insert your email" required="1" autocomplete="off" />
    <input type="email" name="email_r" id="email_r" placeholder="Please confirm your email" required="1" autocomplete="off" />
    </p>
</form>

JS

MyPlugin.checkMatch = function (idInputReferring, idInputRepeat){
   var inputReferring = document.getElementById( idInputReferring );
   var inputRepeat = document.getElementById( idInputRepeat );
   if (inputReferring.value !== inputRepeat.value) {
        inputRepeat.setCustomValidity( "It is must match with the previous input" );
        inputRepeat.checkValidity();
        setTimeout(function() {
        inputRepeat.reportValidity();
        }, 1);

    } else {
        inputRepeat.setCustomValidity('');
        inputRepeat.checkValidity();
    }
};

我该怎么做?

【问题讨论】:

    标签: javascript selenium codeception


    【解决方案1】:

    您可以从输入元素的validationMessage 属性中获取工具提示错误消息。

    【讨论】:

      【解决方案2】:

      一种解决方案(但不能证明浏览器显示工具提示):

      $I->executeJS('return document.getElementById("email_r").validity.invalid;');
      $I->executeJS('return jQuery("#email_r").validationMessage === "It is must match with the previous input"');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-21
        • 1970-01-01
        • 1970-01-01
        • 2017-05-25
        相关资源
        最近更新 更多