Fast authorization. Level— local storage.

Aliaksandr Rasolka
May 11, 2018 · 1 min read
Photo by Alex Holyoake on Unsplash

private void executeJavaScript(final String jsCode) {
((JavascriptExecutor) webDriver).executeScript(jsCode);
}
private void open(final String url) {
webDriver.get(url);
}
private void setItemInLocalStorage(final String item, final String value) {
final String jsCode = String.format(
"window.localStorage.setItem('%s','%s');",
item,
value);
executeJavaScript(jsCode);
}
public void authorizeWithLocalStorage(final AccessToken accessToken) {
open("https://my-supa-dupa-app.com/robots.txt");
setItemInLocalStorage("$accessTokenId", accessToken.getId());
setItemInLocalStorage("$currentUserId", accessToken.getUserId());
}

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade