Configuring portable browser binary via Robot framework - selenium

I need to run my Robot test scripts using portable browsers of specific versions, instead of the one those are installed on the host machine. How can I achieve this? Is there any option available in Selenium Capabilities?
My requirement is for Chrome, IE, and Firefox - all these browser's portable versions.

You can use the following method to specify the binary file location as an experimental option before calling Create Webdriver keyword.
Call Method ${chromeOptions} add_experimental_option prefs ${prefs}
${chromeOptions.binary_location} Set Variable <insert your path here>
Create Webdriver Chrome chrome_options=${chromeOptions}

Can be done this way (same answer as #GPT14, but more complete):
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
${prefs} Create Dictionary
Call Method ${options} add_experimental_option prefs ${prefs}
${options.binary_location} Set Variable ${setYourPathToChromePortableHere}
Create Webdriver Chrome chrome_options=${options}
Go To ${URL}

A possibility is to manipulate the PATH environment variable so that it finds the portable browser first that the installed one (and before calling Create Webdriver or Open Browser).
This can be done using OperatingSystem keywords, like for example, Set Environment Variable.

Related

Selenium: I want to choose which browser to use with invocation in Command Prompt

Currently, I have a .ini file called testcase.ini which looks something like this:
[TEST]
DRIVER_PATH = C:\Python\
BROWSER = CHROME
; BROWSER = EDGE
; BROWSER = FIREFOX
CHROME_PATH = C:\Program Files\Google\Chrome\Application\chrome.exe
; EDGE_PATH = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
; FIREFOX_PATH = C:\Program Files\Mozilla Firefox\firefox.exe
To run my automated tests, I open a command prompt in my Test Plan folder and enter a command like this:
python TestPlan_LoginTest.py
Instead of going in to the testcase config file and commenting out which browsers I don't wish to use when running my automated tests, I'd like to be able to choose the browser when I invoke the test in the command prompt, i.e. something like this:
python TestPlan_LoginTest.py Firefox
or
python TestPlan_LoginTest.py Edge
If I don't include a browser in the invocation, it defaults to Chrome.
Is this possible with unittest? What changes would I need to make and where?
If you're using a pytest plugin called SeleniumBase, you can set the browser from the command-line. (It defaults to "chrome" if not specified.) Example:
pytest test_demo_site.py --edge
pytest my_first_test.py --firefox
Or if you prefer to use your own framework, you can find the necessary code for setting pytest command-line options here in SeleniumBase: pytest_plugin.py
That link shows you about using pytest_addoption(parser): as well as code such as:
parser.addoption(
"--edge",
action="store_true",
dest="use_edge",
default=False""",
)
which lets you customize command-line options for use in tests.

how to not open chromedriver.exe when I run my selenium executable

I made a program that alerts me if there is any seats available
using python, selenium, chromedriver.
Then I made it excutable using pyinstaller with --onefile, -w options since I do not need and I do not want to see any console windows.
But then when I execute my program, chromedriver's console, not sure to call this as a console, shows up.
Is there any way to not see this?
If I understood your question properly, it would mean that you do not wanna see any browser being open up when you run your script.
If that is the case, I would advise headless mode.
options = webdriver.ChromeOptions()
options.add_argument('--window-size=1920,1080')
options.add_argument("--headless")
and then pass the options to driver object like this:
driver = webdriver.Chrome(executable_path = driver_path, options = options)
Using headless mode, you would not see any browser window or console.Your script will run in background.

How to choose which monitor Robot Framework will display test execution?

I'm currently working with 2 monitors, and I've noticed that Robot Framework (using SeleniumLibrary) always open the test execution in the main display that is selected in windows display settings.
Is there any way to choose which monitor will be used to display test execution?
This is how I'm starting the browser. I'm currently using Chrome
Start Browser
Open Browser ${url} ${BROWSER}
... options=add_experimental_option("excludeSwitches", ["enable-logging"])
Maximize Browser Window
Ragnoroct's answer here seems to be a solution: https://stackoverflow.com/a/57545639/16635196.
Chrome has a command-line switch for window position
--window-position=x,y
https://peter.sh/experiments/chromium-command-line-switches/#window-position
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('window-position=2000,0') # opens at x=2000,y=0 from the start
driver = webdriver.Chrome(options=options)
Since I was not using Python directly in the Robot tests, I resorted to directly modifying the Python package source where these options are set. For example, AppData\Local\Programs\Python\Python310\lib\site-packages\QWeb\internal\browser\chrome.py for combination of QWeb and Windows10. Obviously not a good way of doing things in the long run, but virtual environment could be of help here.
Start-maximized didn't work in conjunction with window-position, so I had to additionally use window-size=2560,1440.

How to get rid of the BrowserStack Local extension popup using ChromeDriver Chrome and Selenium

Am just new to automation and trying to automate browserstack. And i successfully logged to browserStack and passed the credentials and clicked on adding chrome extension . There comes the popup and am unable to get the selector for the buttons in the popup.Did any body face across this issue.
Am using an internal tool to automate,behind the scene i guess its using selenium.
Can anybody help me to find the selectors for the popup in browser stack.
Will attach the screenshot
Any help will be hihly helpful,since its a big blocker for me
If you want to Automate a local hosted URL or internal URL you will have to use BrowserStack Local testing feature. There is no need to add this extension.
There is one documentation on How to Perform local testing. All the steps are mentioned in the documents.
BrowserStack Automate Local Testing
If your usecase involves adding the BrowserStack Local or any other extension as a part of your Test Strategy you need to do it programatically.
You can find a couple od relevant discussions in:
How to install extension permanently in geckodriver
How to load extension within chrome driver in selenium with python
Alternative
As an alternative you can enable Enabling Local Testing either programatically through language bindings or through the command-line interface as follows:
Using language bindings:
Java:
import com.browserstack.local.Local;
# creates an instance of Local
Local bsLocal = new Local();
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
# starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
# check if BrowserStack local instance is running
System.out.println(bsLocal.isRunning());
#stop the Local instance
bsLocal.stop();
Steps for using command line:
Download the matching binary for your os: OS X / Linux 32 bit / Linux 64 bit / Windows
Untar/Unzip the binary to a folder/directory on your system.
Open your command-line interface and navigate to the folder containing the Local binary.
Run the binary using the following command:
//OS X/Linux
./BrowserStackLocal --key ACCESS_KEY
//Windows
BrowserStackLocal.exe --key ACCESS_KEY
Configure tests to run with Local Testing connection as follows:
caps.setCapability("browserstack.local", "true");

Selenium Webdriver - How to use Robot Framework with Java

I want to use robot framework with java in Eclipse IDE. i have installed robot framework in Eclipse IDE. How to write script by using robot framework with Selenium web-driver.
If you want to use eclipse as an IDE to write your tests you can use this plugin:
RobotFramework-EclipseIDE
If your goal is to write a java method then call it from robotframework you can use Remote library.
Here are the supported formats writing robotium tests:
Robotium Test Data Sytntax
You can also use maven to run robotframework test from maven project in eclipse:
Robotframework Maven plugin
If you want to write user defined keywords in java which can be used in robot script, import "AnnotationLibrary".
Link is mentioned below and follow the steps AnnotationLibrary
.
try this way.
i am using python language to write test case. python is best way to write a test cases.
my test case file name is test_google_page.robot put this code to test_google_page.robot file and save it. next open command line and go to test_google_page.robot file path and run this command
[user#localhost google_test]$ pybot test_google_page.robot
then you can seen your test case result.
*** Settings ***
Documentation your document
Library Selenium2Library
*** Variables ***
${Url} https://www.google.lk
${Browser} chrome
${Delay} 3s
*** Test Cases ***
load google page
[Documentation] your test case document
OPEN BROWSER ${Url} ${Browser}
Input text id=lst-ib robot framework
sleep ${Delay}
# click button id=<button_id>
# Page Should Contain loglevel=INFO text=<content>
Capture Page Screenshot filename=test_result.png
[Teardown] CLOSE BROWSER