How to launch chrome or any browser using RobotFramework as normally it is installed for usage, not like as a clean new installed chrome

How to launch chrome or any browser using RobotFramework as normally it is installed for usage, not like as a clean new installed chrome.

The problem that I am having is that I do not want to login my website that I am testing again and again as it also requires two-factor authentication. How to launch chrome or any other browser that it remembers everything as I use it normally where I use gmail, linkedin etc and I do not need to login there again and again.
Sincere Regards

Hi @EagerToLearn,

  • Which Library are you using to launch the browser?
  • Which Browser are you using?

For example Open Browser from SeleniumLibrary has a ff_profile_dir argument, and i believe similar thing can be achieved with Chrome using options.

You can acheive something Similar with Browser Library and Save Storage State

Hopefully that helps you in the right direction,

Dave.

Hi Dave,
Thank you for you reply. I will try the solution you have told. What I am doing is this:

*** Settings ***
Library SeleniumLibrary

*** Variables ***
${URL}= https://www.ebay.com
${Web_Browser}= chrome

*** Keywords ***
Practicising Checkboxes
Open Browser ${URL} ${Web_Browser}
Maximize Browser Window
Sleep 4s
*** Test Cases ***
Practice Checkboxes
Practicising Checkboxes

So after this I get a chrom window which seems to be as if it is just installed :slightly_smiling_face:
Sincere Regards

Yes the default behaviour is to open the browser with a blank profile, this is by design, It’s not unique to robot framework Selenium does this so all testing tools that rely on Selenium also do this.

Dave.

Hi Dave,

First I tried to create and save the profile:

*** Settings ***
Library SeleniumLibrary
Library Browser

#*** Tasks ***
#Click Element When Visible xpath:id=“accept-choices”

*** Variables ***
${URL}= http://www.some_blah_blahwebsite.com
${Web_Browser}= firefox
${Executable_Path_To_Chrome}= C:\Program Files\Google\Chrome\Application\chrome.exe
${Executable_Path_To_Firefox}= C:\Program Files\Mozilla Firefox\firefox.exe

${EMAIL_INPUT_FIELD}= name:loginformat
${EMAIL}= eager_to_learn@emailaddress.com

${NEXT_BUTTON}= id:Button9

${PASSWORD_FIELD}= id:password_fld
${PASSWORD}= qwerty

${IDENTITY}= xpath://*[@id=“id_verify”]

${VERIFY_BUTTON}= id:idSubmit_REMEMBER

${CHECKBOX_REMEMBER}= name:REMEMBER

*** Keywords ***
Practicising SaveProfile
SeleniumLibrary.Open Browser ${URL} ${Web_Browser} ${Executable_Path_To_Firefox}
Maximize Browser Window
Sleep 60s

*** Test Cases ***
SaveProfile Test for Firefox
New context
SeleniumLibrary.Open Browser ${URL} ${Web_Browser} ${Executable_Path_To_Firefox}
Maximize Browser Window
Sleep 10s
#New Page ${URL}
# Perform login
#Fill Secret ${EMAIL_INPUT_FIELD} ${EMAIL}
Input Text ${EMAIL_INPUT_FIELD} ${EMAIL}
#Fill Secret ${PASSWORD_FIELD} ${PASSWORD}
#Input Password ${PASSWORD_FIELD} ${PASSWORD}
Sleep 10s
Click Button ${NEXT_BUTTON}
Sleep 10s
Input Password ${PASSWORD_FIELD} ${PASSWORD}
Sleep 10s
Click Button ${NEXT_BUTTON}
Sleep 20s
Click Element ${IDENTITY}
Sleep 40s
#CLICK the sms field
Click Button ${VERIFY_BUTTON}
Sleep 20s
Select Checkbox ${CHECKBOX_REMEMBER}
Sleep 20s
Click Button ${NEXT_BUTTON}
Sleep 40s

#  Save storage to disk
${state_file}=          Save Storage State

#  Create new context with saved state
# No new page is launched in my case with these codes below

New context         storageState=${state_file}
New Page            ${URL}    

#SeleniumLibrary.Open Browser ${URL} ${Web_Browser} ${Executable_Path_To_Chrome}
#Maximize Browser Window
Sleep 60s

The profile that is created in the D:\EagerToLearn\MY_LEARNING\PycharmProjects\RobotFWTutorial\Results\browser/browser/state folder in .json format like this:

+++++++++++++++++++++++++
{
“cookies”: ,
“origins”:
}
+++++++++++++++++++++++++

Then from searching I found: that if we type in Firefox: about:support
It shows Profile Folder:
C:\Users\EagerToLearn\AppData\Roaming\Mozilla\Firefox\Profiles\cjakdash5235x.EagerToLearn_test_Profile\sessionstore-backups


It has three files:

  • previous.jsonlz4
  • upgrade.jsonlz4-20231211174248
  • recovery.jsonlz4 – seems to have more data (needed for my task to accomplish) than previous.jsonlz4

I copied them to a directory and referred them in my test but seemingly no luck.


I am trying this code but it does not launch the firefox with the profile:

*** Settings ***
Library SeleniumLibrary
Library Browser

*** Variables ***
${URL}= http://www.some_blah_blahwebsite.com
${WEB_BROWSER}= firefox

#I tried these different ways to reach Firefox profile for the variable: ${ff}
#${FF_PROFILE_DIR_FOR_FIREFOX}= C:\Users\EagerToLearn\AppData\Local\Mozilla\Firefox\Profiles

#${ff}= C://Users//EagerToLearn//AppData//Roaming//Mozilla//Firefox//Profiles//cjakdash5235x.EagerToLearn_test_Profile

#${ff}= D:\EagerToLearn\MY_LEARNING\PycharmProjects\RobotFWTutorial\Resources\RESOURCES_FOR_some_blah_blahwebsite\PROFILES\recovery.jsonlz4

#${ff}= D://EagerToLearn//MY_LEARNING//PycharmProjects//RobotFWTutorial//Resources//RESOURCES_FOR_some_blah_blahwebsite//PROFILES//recovery.jsonlz4

${ff}= “D://EagerToLearn//MY_LEARNING//PycharmProjects//RobotFWTutorial//Resources//RESOURCES_FOR_some_blah_blahwebsite//PROFILES//recovery.jsonlz4”

*** Keywords ***
LAUNCH some_blah_blahwebsite WEBSITE

SeleniumLibrary.Open Browser        ${URL}      ${WEB_BROWSER}      ff_profile_dir=${ff}    
Maximize Browser Window
SeleniumLibrary.Go To    ${URL}
Sleep    60s

*** Test Cases ***
LAUNCH some_blah_blahwebsite WEBSITE TEST
LAUNCH some_blah_blahwebsite WEBSITE

Then I get this exception:
AttributeError: ‘FirefoxProfile’ object has no attribute ‘“D://EagerToLearn//MY_LEARNING//PycharmProjects//RobotFWTutorial//Resources//RESOURCES_FOR_some_blah_blahwebsite//PROFILES//recovery.jsonlz4”’

I wonder is there some code that can launch firefox or any browser with its saved profile. :slight_smile:
Sincere Regards
EagerToLearn

You can’t mix and match keyword from those libraries, choose one and use only it’s keywords, to be clear the Save Storage State keyword from Browser Library will only work on the browser window you opened with New Context, it will not work with SeleniumLibrary’s browser (it can’t).

I personally have never used the stored profile features as I never needed them, so I’ll try my best to help but I’m just following the documentation.

Dave.