Powered By GitBook
Google Autologin
Motivation
Selenium opens the browser in incognito mode. However, for some test scenarios, we would like to login to Google account. Instead of doing it as part of the test flow or running it as a setup method we can do it automatically.
How to do this with TestProject?
    1.
    Chrome keeps the profile locally in
C:\Users\{username}\AppData\Local\Google\Chrome\User Data.
We need to go to the parent folder (Chrome) and do one of the following options:
    Create a copy of the User Data folder, let’s call it Test User Data.
    Create a new Chrome profile and set the required actions in it, and then
copy this profile (will probably appear as Person 2) to the Test User Data folder instead of the default user (change the name).
Why are we creating this new folder? If any instance of Chrome browser is open while we are trying to create a new WebDriver instance the operation will fail with
an error
InvalidArgumentException: Message: invalid argument: user data directory
is already in use, please specify a unique value for --user-data-dir
argument, or don't use --user-data-dir
So, to avoid closing the browser every time we run a test (which is quite
impossible when we are using TestProject) we use a copy of the profile.
3. Now we want to use the new profile
    In TestProject platform create a job and add your test to it. Now click on
the Set Driver Desired Capabilities icon
And add
1
{
2
"goog:chromeOptions": {
3
"args": [
4
"user-data-dir=C:/Users/dorbe/AppData/Local/Google/Chrome/User Data",
5
"profile-directory=Profile 2"
6
]
7
}
8
}
Copied!
    If you are using the SDK just add options (Java code)
1
ChromeOptions options = new ChromeOptions();
2
options.addArguments("--user-data-dir=PATH_TO/Test User Data", "profile-directory=Profile 2");
Copied!
You can see the current profile you are using by navigating to chrome://version inside your Chromr browser.
Last modified 6mo ago
Copy link