How to introduce delay between tests in protractor

萝らか妹 提交于 2021-01-28 08:11:41

问题


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.

please find the code snippet as below;

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.?


回答1:


I'm not sure I understand the question but if you just want to see if your "confirmInstructions" is clicked, you should use a debugger and set a breakpoint before the method




回答2:


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));
}

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

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.



来源:https://stackoverflow.com/questions/56127716/how-to-introduce-delay-between-tests-in-protractor

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