How to do conditional browser interactions with intern

99封情书 提交于 2019-12-02 04:49:05

In Intern 2, simply use the normal find command:

var remote = this.remote;
remote.get(url)
    .findById('foo')
    .then(function (element) {
        // exists
    }, function () {
        // does not exist
    });

In Intern 1, if you need to conditionally branch, you’ll need to stop and add new instructions based on the result of your check.

var remote = this.remote;
remote.get(url)
    .elementByIdIfExists('foo')
    .then(function (element) {
        if (element) {
            remote.clickElement()
                .type('foo');
                // ...etc.
        }
    });

This should work in Intern 1.1 only if you are adding new commands to the remote promise chain when there are no other already-existing commands pending. Intern 1.2 will contain improvements that eliminate this restriction. This is issue #14.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!