Fastening execution of selenium scripts by replicating repetitive UI navigation through webservice calls & selenium cookie management

There are many ways to expedite selenium scripts' execution , for-ex using css locators , failing fast , parallelizing tests using selenium grid architecture , using dockerized grid etc . One more thing which I tried last week and want to add in this list is [using web services to perform repetitive ui setup & by passing webservice session's cookies to selenium session] . Read following post carefully for actual implementation of above idea.

Our scenario

We have thousands of selenium scripts in our organization. These scripts do same ui login & home page navigation before performing/verifying actual functionality . Because of that significant amount of time goes in performing this setup. Since it is required in each and every test, we can't avoid it . Hence we pondered upon performing these setup(login & some ui navigation) using webservice calls instead of selenium ui navigation . Here is what we did for it

We created a webclient (implementation of basic httpclient) . It provided us platform to call different rest/soap webservices of my AUT(application under test) . Using this webclient we implemented my AUT's login and some navigational functionalities(setup).

We initialized our selenium webdriver using (FirefoxDriver / ChromeDriver) & navigated to login page of our application . Till now we have just navigated to login page and not performed actual login(neither through webservice nor through selenium).

Now we initialized our webclient's object and called login web service (providing username & password) . Once done , we had required authentication token & genuine session created . we then called some other web services using above authentication token to navigate to some setup modules . Now our object of webclient had required session details (like http headers , cookies) .

Now we wrote getter method to retrieve cookies from webclient & fed these cookies to selenium webdriver using function call (Most Imp step)

Loop through all webclient's cookie and set in selenium driver's ession using driver.manage.addcookie(cookie) // this is the most imp step of whole flow

That's it . Once we were done setting cookies in webdriver's object , we were able to directly navigate (using driver.get() / driver.navigate() ) to module to perform actual scenarios .

This is how we replicated repetitive UI navigation/flows using webservice calls and selenium cooking management.

Sameer Jethvani check out BrowserStack and how to run Selenium Grid in the Cloud: https://www.browserstack.com/automate

Like
Reply

To view or add a comment, sign in

Others also viewed

Explore content categories