How to install browser extensions on saucelabs? - selenium

I want to install an browser extension before my tests starts. I read on the documentation here that I should create a prerun executable to do this for me. However I am not sure how to this. I have no experience with creating executables

Using the pre-run will only upload the extension onto the SauceLabs Virtual Machine, it won't install it onto the respective browser.
If you want the extension to be installed on the browsers, you may want to consider setting a custom Firefox profile or Chrome options.
Here is a simple Java Example for setting a firefox profile (make sure to use the full path otherwise you will likely get an error):
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(<PATH TO EXTENSION>));
caps.setCapability(FirefoxDriver.PROFILE, profile);

Related

How can I create a custom firefox profile on a centos vm

I have created a centos vm. Installed maven, firefox on it and placed selenium automation code to test my web application on it. The only issue is my automation code works on a specific profile where I need to enable the 'Open new windows in a new tab instead' firefox setting.
How can I create a custom firefox profile including this setting on a vm ?
I did a ssh on my vm and then did
firefox -CreateProfile Selenium
I cant find on which location this profile is created. Also I still could not figure out how to add custom settings, as the above just creates a profile I guess.
Here is a description on how to create (and move and remove) Firefox profiles using the built-in Profile Manager. On linux it is usually located in $HOME/.mozilla/firefox/. Profile names are mapped to directories in profiles.ini
A custom profile can be used both programmatically (using FirefoxProfile, FirefoxOptions, FirefoxDriver) or by command line parameter.

Run Selenium Application on different machine than where it was created

I have developed a Console App using VS2015 which uses Selenium WebDriver to test some websites.
I now want to install this app onto a server and run it there.
I have already installed the app on the server, but when I try to run it, I get an error saying that "Firefox binary couldn't be found in PATH or default". Firefox is installed in the default path C:\Program Files\Mozilla.
Have you got any suggestions on this? Do I need to install any part of Selenium on the server? (Selenium Standalone Server for example)
The server is running Windows Server 2012 R2
Looks like it's unable to find the Firefox binary on its own. So you have to specify the binary of Firefox explicitly. Use the below code to find the Firefox binary
FirefoxBinary binary = new FirefoxBinary(new File("path/to/binary"));
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(binary, profile);
What I would recommend is for you to be using Firefox binary in your test suites and call the path of the executable from a properties file so that you don't have to compile all of your test cases again.
The issue was actually caused by the environment variable %PATH%. The variable didn't contain the path for Firefox default installation, which is
C:\Program Files\Mozilla Firefox
To fix the problem, I simply added that path to the environment variable %PATH% (you can find it by clicking Start, typing "environment variables", and clicking on "Environment Variables..." button on the bottom right of the System Properties tab that open when you look for "environment variables" in the Start menu.
That solved the issue.
Thank you Khaja for you answer anyways.

Firefox is showing "Cannot find firefox binary in PATH." error in MAC OS

Firefox is showing "Cannot find firefox binary in PATH." error in MAC OS.
As per my understanding this issue occurs if the Mozilla is not installed in their default location. I am new in MAC OS
I have also tried with firefox profile and already I have set selenium provided DesiredCapabilities
WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("/Applications/Firefox.app/Contents/MacOS/firefox-bin")), profile);
I have also tried with different path of mozilla in MAC OS like:-
/Applications/Firefox.app/Contents/MacOS/firefox-bin
/Applications/Firefox.app/Contents/MacOS/firefox
/Applications/Firefox.app
Also please provide a snippet for the same.
Chrome is working fine for me in MAC OS. Only Mozilla is creating problem
Surely, I am missing something. I am attaching the snapshot regarding same.
Also, Is there any method present by which I can locate any application installed location using java code?
According to https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver there is a property you have to set to set the binary path:
webdriver.firefox.bin
so i assume you have to do following:
System.setProperty("webdriver.firefox.bin","/Applications/Firefox.app/Contents/MacOS/firefox-bin");
WebDriver driver = new FirefoxDriver();
I hope this helps :)
If you have installed firefox, check whether the Firefox application is in the /Applications folder. If not move the application to /Application folder and run the test again.
If above worked, you don't have to add a system property "webdriver.firefox.bin"
Possibly updated for the current situation with this I did this:
Installed geckodriver, available since 2018, to /usr/local/bin (arbitrary choice and made sure it could execute. This placement made it unnecessary to add it to my $PATH.
Installed Firefox to /Applications (I had the developer version)
Added this line to my setUp method: driver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));
All this in macOS 10.11 "Big Sur" (aarch64) using current selenium.

Testing with Web Driver and Selenium through Codeception

I know I'll get crap for this but it's worth it if someone can help.
I can't find a guide, tutorial, or instructions anywhere for installing web driver on a windows machine. I've got a site running on a homestead vagrant box and need a way of running acceptance tests locally. I had tests setup using PhpBrowser but those don't simulate JavaScript. If anyone knows of a guide to do this or a better way to run acceptance tests it would help immensely. I've got Ajax calls so PhpBrowser and resources like it won't work.
Thanks!
Just download the selenium webserver the jar file and run it in a command shell with java -jar selenium-server-standalone-2.43.1.jar. The selenium server will now listen on the default port 4444. If you run your test it should work as expected. Keep in mind that selenium webserver opens firefox and uses it for testing. It's pretty useful for watching the test cases.
If you want a headless test (no visible browser) you need to download phantomjs. Unpack it and run the phantomjs.exe with --webdriver=4444 as an argument (so phantomjs.exe --webdriver=4444).
Download and Run the selenium-server-standalone-2.43.1.jar as stated in the comment. I had to add firefox_binary: C:\Program Files (x86)\Mozilla Firefox\firefox.exe under capabilities: in my acceptance.suite.yml file. I also added it to the path variable but I'm not sure if that made a difference. Had to add the firefox_binary to make it work.

Selenium and HTTPS/SSL

I'm running selenium-rc 1.0.3 on a Mac OS X & Windows 7 and both seem to be giving my the annoying accept cert error in firefox. In reading the docs they say I should be able to just use the *firefox run mode and rc should take care of it for me via a proxy or something, but this appears to not work. The only solution that I was able to find on the internet was to create a skeleton profile and pass the path into the rc startup, but thats not a real option. As that doesn't solve problems of testing in IE/Chrome/Safari. Does any know of any other solution that will work.
Selenium-RC docs on HTTPS - http://seleniumhq.org/docs/05_selenium_rc.html#handling-https-and-security-popups
I have tried the solution given by this article (Thanks elliot) and it works well for me! Basically
1. Create a firefox profile:
a. Starting your firefox -ProfileManager (or firefox -P) in cmd.exe (make sure the firefox installation folder path is in your path environment variable, by default it should be just created when you installed firefox) and create a new profile.
b. Select this new profile to browse to the HTTPS URL and accept the self-signed certificate when prompted.
c. Go to the Firefox profile directory.
d. Delete everything in the directory except for the cert_override.txt and cert8.db files.
2. Run your selenium RC server using this profile:
such as java -jar selenium-server.jar -firefoxProfileTemplate c:/Firefox_Profile
If this is an issue with self-signed certificates, you could try using the RCE plugin for Firefox in a custom profile: http://sejq.blogspot.com/2009/01/remember-certificate-exception.html
Internet Explorer's warnings can be disabled through the advanced settings (specifics depend on the version of IE). Worth Googling around for a solution.
For Google Chrome I believe this is an unresolved issue related to: http://code.google.com/p/chromium/issues/detail?id=2010&can=5&colspec=ID%20Stars%20Pri%20Area%20Feature%20Type%20Status%20Summary%20Modified%20Owner%20Mstone%20OS