spidy
spidy

Reputation: 269

Protractor writing a cleaner test cases without using browser.sleep

Im new to protractor and jasmine and I use lot of browser.sleep to make my test cases work

it('Procedure tab-', function() {

        element(by.linkText('Medical History')).click();
        browser.sleep(500)
        element(by.linkText('Personal History')).click();
        browser.sleep(200)
        element(by.linkText('Procedure')).click();
        browser.sleep(500)
        element(by.css('[data-ng-show="ptab.index  === 1"] > [profile="profile"] > #medicalhistory > .card > [header="header"] > .card-header-bg > .title-header > .row > [ui-sref=".procedure.new"] > [data-ng-hide="important"]')).click();
        browser.sleep(500)
        $('label[for="dis4Appendicitis"]').click();
        browser.sleep(2000)
    })

What could be more efficient way to write a test case without using browser.sleep........I have been using sleeps because of slower internet connectivity etc....

Any help is appreciated

Upvotes: 0

Views: 166

Answers (1)

giri-sh
giri-sh

Reputation: 6962

An efficient way to perform any test is by using implicit and explicit waits. Implicit wait can be added in conf.js file so that protractor takes it into consideration at the very beginning of test execution. Here's an example -

browser.manage().timeouts().implicitlyWait(10000); //Wait for 10 seconds before failing particular actions/operations

And explicit waits can be achieved using wait() function coupled with ExpectedConditions.

This efficiently replaces browser.sleep() method by continuously checking for the expected condition specified.

Here's how to use it -

var EC = protractor.ExpectedConditions;
var elem = element(by.css(LOCATOR));
browser.wait(EC.visibilityOf(elem), 10000); //Wait for 10 seconds before failing the step

Hope it helps.

Upvotes: 3

Related Questions