如何在量角器中引入两次测试之间的延迟

问题描述:

我正在用黄瓜探索量角器工具,并且测试执行得非常快..为了知道是否真的单击了元素,我正在使用sleep()方法,但失败了.我也在预期条件下使用另一种方法wait(),但是也失败了..实际上,我了解到link元素本身上的click()方法失败了.也就是说,无法单击我想要的元素,但是当我在控制台元素上打印的是打印其所有属性和方法.

I am exploring protractor tool with cucumber and test is executing super fast.. in order to know if really elements are getting clicked or not, I am using sleep() method but failing. I am also using another method wait() with expected conditions which is also failing.. In fact, I understood click() method on the link element itself is failing.. That is, unable to click on element which I desired, however when I print on console element is printing all its attributes and methods.

请找到以下代码段;

When(/^I click on "(.*?)" link$/,  (callback) => {
    console.log("Clicking... ");
    browser.wait(EC.visibilityOf(login.confirmInstructions), 5*1000, "Waiting for Confirmation link...");
    var confirmLink  = login.confirmInstructions;
    var isClickable  = EC.elementToBeClickable(confirmLink);
    browser.wait(isClickable, 10*1000, "Element clickable");
    confirmLink.click();

    browser.sleep(10*10000);
    login.confirmInstructions.click();
    //browser.wait(validateText(element(by.binding('myvar'))), 5000, "");
    //browser.wait(EC.presenceOf(confirmation.confirmScreen), 60*1000);
    console.log("waited");
    return callback;
});

我在这里想念的是什么?

What I am missing here.?

我了解,在量角器中等待Web元素的最佳方法是使用wait()而不是sleep.但是,我一直在寻找两种方式(通过使用等待/睡眠)来减慢测试的执行速度,因为在实现测试方案以识别Web元素时这很有用.最后,下面是我现在正在使用的方法..但是,如果还有更好的处理方法,请发表您的评论.

I understood, the best way to wait for web elements in protractor is to use, wait() rather than sleep. However, I was looking either of the way (by using wait / sleep) to slow down the test execution, as it is useful while implementing test scenarios in order to recognize web elements. Finally, following method for now I am using it.. but still if there is a better way to handle please put your comments..

const sleep = (milliseconds) => {
    return new Promise(resolve => setTimeout(resolve, milliseconds));
}

并从我的函数中调用sleep: await sleep(2000);

and calling sleep from my function as: await sleep(2000);

就目前而言,我可以继续编写测试..我也确信量角器API中有更好的方法,但是找不到它的实现.

For now, I am able to move forward with writing tests.. I am also sure there is a better way in protractor API, yet to find it's implementation.