几个元素之后的连锁操作已被检索

为了testing,我们必须填写一个复杂的页面使用实习生/ leadfoot。 页面的每个部分都由一个单独的函数来处理,它接收必要的元素和input数据。

现在我们有这个问题,子function中这些元素的行为不能再链接了,因为它们是元素而不是命令。

是否有可能再次链接操作? 我尝试了很多,使用setContext()或自定义命令创build一个新的命令,但到目前为止还没有成功。

 let inputs; return this.remote .get('some/url') .findAllByTagName('input') // Finds two input elements .then(inputElements=> inputs = inputElements) .then(()=> Promise.all([ inputs[0].clearValue(), // I would like to be able to write: inputs[0].clearValue().type('a') inputs[1].clearValue(), ])) .then(()=> Promise.all([ inputs[0].type('a'), inputs[1].type('b'), ])) 

元素与Commands共享许多相同的方法,但是它们具有不同的API。 主要区别在于表示动作的Command方法返回Commands(一个Command类似promise,并在动作完成时parsing),但表示动作的Element方法不返回元素(元素不是promise)。 这意味着你不能直接链接许多Element方法。

对于问题中描述的情况,您可以执行以下操作:

 function clearAndType(input, value) { return remote.then(function (_, setContext) { // setContext is always the last argument to a Command then() // callback; the value returned by the previous Command is the // first argument, which is ignored here setContext(input); }) .clearValue() .type(value); } var remote = this.remote; return this.remote .get('some/url') .findAllByTagName('input') .then(function (inputs) { return Promise.all([ clearAndType(inputs[0], 'a'), clearAndType(inputs[1], 'b'), // ... ]); })