Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Every time when I run my test first step is login and then I get to the desired page. I run this test often log in operation takes a lot of time.

How can I pass a login operation?

Using Chrome and Firefox drivers, java language.

1 Answer

0 votes
by (62.9k points)

Create cookies using the Java API as follows:

Cookie ck = new Cookie("name", "value");

driver.manage().addCookie(ck);

Create cookies using the Python API as follows:

driver.add_cookie({'name': 'foo', 'value': 'bar'})

For those who need to set more detailed information on Cookie besides name and value you can use:

 Cookie cookie = new Cookie.Builder("name", "value")

    .domain(".mydomain.com")

    .expiresOn(new Date(2019, 07, 18))

    .isHttpOnly(true)

    .isSecure(false)

    .path("/mypath")

    .build();

driver.manage().addCookie(cookie);

I hope this helps!

Browse Categories

...