Karving
Karving

Reputation: 56

How to start browser in WebDriver with custom localStorage set

I want to speed up my Selenium tests and noticed that a lot of time is being spent on login procedure.

Login on web application is implemented via localStorage session token (probably OAuth 2.0). I know how to set it once a browser starts and login page loads:

localStorage.setItem(key, value)

It works great. But is it possible to make the browser to pick up custom localStorage using Selenium (Java).

Is it profile?

Upvotes: 2

Views: 2644

Answers (1)

Alejo Espitia
Alejo Espitia

Reputation: 11

Well this works for me in python

driver.excute_script('javascript:localStorage.(funtion of localStorage)')

so I suppose well you can set up a validation token like I use for test, and of course I get my auth_token from the database first, but it works like this

driver.excuteScript('javascript:localStorage.token="your validation token";');

should work

Upvotes: 1

Related Questions