How to do conditional browser interactions with intern

后端 未结 1 519
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 11:31

With the promised web driver I would like to check if an element exists on the page, then login if it does, otherwise continue with the promise chain.

Is this not possib

相关标签:
1条回答
  • 2021-01-25 11:47

    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.

    0 讨论(0)
提交回复
热议问题