How do I run Firebug within Selenium WebDriver (Selenium 2)? - java

What's the best way to activate Firebug in Firefox when running Selenium 2?
Edit: Ok, I realize "best" is open to interpretation, but the profile-based solution really used to be a pain with selenium 1.0. So any alternative is considered better until proved worse ;)

You can create your profile in code and dynamically add required add-ons. Let's assume that you saved Firebug XPI into the C:\FF_Profile folder as firebug.xpi (go to Firebug download page, right-click on the "Add To Firefox" and save as C:\FF_Profile\firebug.xpi).
In code:
final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(firebugPath));
// Add more if needed
WebDriver driver = new FirefoxDriver(profile);
This is described in WebDriver FAQ

Do you mean having firebug installed in the browser instance that webdriver launches? If so, you can pass an extension when you instantiate the driver, but the eaisest way is to create a firefox profile with firebug installed and then use the following code before you instantiate the driver:
System.setProperty("webdriver.firefox.profile", "NAME_OF_FIREFOX_PROFILE_WITH_FIREBUG");

Just reference your profile by name. Example in Ruby:
#driver = Selenium::WebDriver.for :firefox, :profile => "default"
Then, load Firefox normally, and add your desired extensions. They will now show up in your Selenium test runs.

Apparently the way the firefox-profile options are consumed has changed in Selenium WebDriver.
The old commandline (Selenium RC):
java -jar selenium-2.28.0.jar -firefoxProfileTemplate ~/.mozilla/firefox/3knu5vz0.selenium
Updated for WebDriver: (note that it wants the profile name rather than the directory)
java -jar selenium-2.28.0.jar -Dwebdriver.firefox.profile=selenium

modify your firefox location to something like
C:\Users\user-name\AppData\Roaming\Mozilla\Firefox\Profiles\sgmqi7hy.default
launch your firefox from selenium / webdriver
make all your required settings
close and restart firefox browser from selenium / webdriver
that's it, it solves your problem !!

I found a profiles.ini in ~/.mozialla/firefox/. In there was a profile named default, which I specified a like the following and then firefox was opened in test just like I opened it regularly (with all plugins etc).
java -jar selenium.jar -Dwebdriver.firefox.profile=default

If none of the above option works. Then try this.
1) Open terminal and type below command (close all existing firefox
sessions first)
firefox -p
2) This will open an option to create a new Firefox profile.
3) Create a profile lets say "SELENIUM".
4) Once the firefox is open straight away install firebug or any
other plugins extension that you want. once done close the window.
5) Now load this new profile via selenium , use below java
statements.
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
6) Done. Enjoy.

I have observed that the firebug is adding to browser and it is disabled by default and not enabled ,when i add firebug to firefox at runtime by using webdriver. So to make it enable we may need to add the below line to profile.
profile.setEnableNativeEvents(true);

Assuming that, Firebug is installed. Your objective is to run Firebug. Firebug can be run/execute by pressing F12 key. So Firebug can be run by following command of Selenium WebDriver with Java:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();

Related

Open firefox devtools programmatically with FirefoxProfile

How can I launch Firefox 52 with opened devtools using selenium and Java?
Before the merge of Firebug into the Firefox DevTools I used FirefoxProfile to open the console programmatically:
profile.setPreference("extensions.firebug.console.enableSites", true);
etc.
But Firebug does not work anymore now.
So what is the proper way to launch with opened network or console tab?
And also, is there any analog extension to FirePath to launch automatically and use instead of the currently broken FirePath extension?
I managed to launch Firefox with given page and native devtools open from command line using -devtools parameter:
firefox -no-remote -profile "c:\deleteme" -devtools -url "http://example.com/"
It seems to be possible to pass that parameter to the WebDriver by calling
addCommandLineOptions("-devtools") on the FirefoxBinary instance.
(Via How can I tell selenium to start firefox with certain commandline options?.)
Or in Node perhaps by firefox.Options().setBinary(…).addArguments("-devtools")
Spotted the parameter in firefox -help | more, but alas, seems that not all information presented there as well as info given at Command_Line_Options MDC page are still valid. The -devtools one is missing at the MDN page at this moment.

Using selenium, not able to open Firefox with a saved profile

I have created a new Firefox profile, and want to call the profile in my selenium code to load Firefox using this profile (plugins, etc).
Given the code below.
System.setProperty("webdriver.gecko.driver","D:\\Software\\Firefox\\Driver\\geckodriver-v0.10.0-win64\\geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Dev 8\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\j3yl2vj7.MyTest02"));
WebDriver driver = new FirefoxDriver(profile);
It opens Firefox with the default settings, instead of with my particular profile with the plugins etc.
Version information:
Selenium : selenium-java-3.0.0-beta2
Java : Java SE 1.7
Firefox : 45.0.2
According to this blog article, you need to run Selenium 3.0 with Java 8.

Selenium 2.53 not working on Firefox 47

I am getting error while using Firefox with WebDriver.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms.
Firefox version:47.0
Selenium:2.53.0
Windows 10 64 bit
Is anyone getting a similar issue or any idea what is the solution for this? It's working fine with Chrome but with Firefox none of the URLs are getting loaded.
Unfortunately Selenium WebDriver 2.53.0 is not compatible with Firefox 47.0. The WebDriver component which handles Firefox browsers (FirefoxDriver) will be discontinued. As of version 3.0, Selenium WebDriver will need the geckodriver binary to manage Firefox browsers. More info here and here.
Therefore, in order to use Firefox 47.0 as browser with Selenium WebDriver 2.53.0, you need to download the Firefox driver (which is a binary file called geckodriver as of version 0.8.0, and formerly wires) and export its absolute path to the variable webdriver.gecko.driver as a system property in your Java code:
System.setProperty("webdriver.gecko.driver", "/path/to/geckodriver");
Luckily, the library WebDriverManager can do this work for you, i.e. download the proper Marionette binary for your machine (Linux, Mac, or Windows) and export the value of the proper system property. To use this library, you need to include this dependency into your project:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
... and then execute this line in your program before using WebDriver:
WebDriverManager.firefoxdriver().setup();
A complete running example of a JUnit 4 test case using WebDriver could be as follows:
public class FirefoxTest {
protected WebDriver driver;
#BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
#Before
public void setupTest() {
driver = new FirefoxDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
// Your test code here
}
}
Take into account that Marionette will be the only option for future (for WebDriver 3+ and Firefox 48+), but currently (version 0.9.0 at writing time) is not very stable. Take a look to the Marionette roadmap for further details.
UPDATE
Selenium WebDriver 2.53.1 has been released on 30th June 2016. FirefoxDriver is working again with Firefox 47.0.1 as browser.
Try using firefox 46.0.1. It best matches with Selenium 2.53
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
I had the same issue and found out that you need to switch drivers because support was dropped. Instead of using the Firefox Driver, you need to use the Marionette Driver in order to run your tests. I am currently working through the setup myself and can post some suggested steps if you'd like when I have a working example.
Here are the steps I followed to get this working on my Java environment on Mac (worked for me in my Linux installations (Fedora, CentOS and Ubuntu) as well):
Download the nightly executable from the releases page
Unpack the archive
Create a directory for Marionette (i.e., mkdir -p /opt/marionette)
Move the unpacked executable file to the directory you made
Update your $PATH to include the executable (also, edit your .bash_profile if you want)
:bangbang: Make sure you chmod +x /opt/marionette/wires-x.x.x so that it is executable
In your launch, make sure you use the following code below (it is what I used on Mac)
Quick Note
Still not working as expected, but at least gets the browser launched now. Need to figure out why - right now it looks like I need to rewrite my tests to get it to work.
Java Snippet
WebDriver browser = new MarionetteDriver();
System.setProperty("webdriver.gecko.driver", "/opt/marionette/wires-0.7.1-OSX");
If you're on OSX using Homebrew, you can install old Firefox versions via brew cask:
brew tap goldcaddy77/firefox
brew cask install firefox-46 # or whatever version you want
After installing, you'll just need to rename your FF executable in the Applications directory to "Firefox".
More info can be found at the git repo homebrew-firefox. Props to smclernon for creating the original cask.
If you're on a Mac do brew install geckodriver and off you go!
In case anyone is wondering how to use Marionette in C#.
FirefoxProfile profile = new FirefoxProfile(); // Your custom profile
var service = FirefoxDriverService.CreateDefaultService("DirectoryContainingTheDriver", "geckodriver.exe");
// Set the binary path if you want to launch the release version of Firefox.
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
var option = new FirefoxProfileOptions(profile) { IsMarionette = true };
var driver = new FirefoxDriver(
service,
option,
TimeSpan.FromSeconds(30));
Overriding FirefoxOptions to provide the function to add additional capability and set Firefox profile because selenium v53 doesn't provide that function yet.
public class FirefoxProfileOptions : FirefoxOptions
{
private DesiredCapabilities _capabilities;
public FirefoxProfileOptions()
: base()
{
_capabilities = DesiredCapabilities.Firefox();
_capabilities.SetCapability("marionette", this.IsMarionette);
}
public FirefoxProfileOptions(FirefoxProfile profile)
: this()
{
_capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());
}
public override void AddAdditionalCapability(string capabilityName, object capabilityValue)
{
_capabilities.SetCapability(capabilityName, capabilityValue);
}
public override ICapabilities ToCapabilities()
{
return _capabilities;
}
}
Note: Launching with profile doesn't work with FF 47, it works with FF 50 Nightly.
However, we tried to convert our test to use Marionette, and it's just not viable at the moment because the implementation of the driver is either not completed or buggy. I'd suggest people downgrade their Firefox at this moment.
New Selenium libraries are now out, according to: https://github.com/SeleniumHQ/selenium/issues/2110
The download page http://www.seleniumhq.org/download/ seems not to be updated just yet, but by adding 1 to the minor version in the link, I could download the C# version: http://selenium-release.storage.googleapis.com/2.53/selenium-dotnet-2.53.1.zip
It works for me with Firefox 47.0.1.
As a side note, I was able build just the webdriver.xpi Firefox extension from the master branch in GitHub, by running ./go //javascript/firefox-driver:webdriver:run – which gave an error message but did build the build/javascript/firefox-driver/webdriver.xpi file, which I could rename (to avoid a name clash) and successfully load with the FirefoxProfile.AddExtension method. That was a reasonable workaround without having to rebuild the entire Selenium library.
Its a FF47 issue
https://github.com/SeleniumHQ/selenium/issues/2110
Please downgrade to FF 46 or below (or try out FF48 developer https://developer.mozilla.org/en-US/Firefox/Releases/48)
Instructions on how to downgrade:
https://www.liberiangeek.net/2012/04/how-to-install-previous-versions-of-firefox-in-ubuntu-12-04-precise-pangolin/
Or if you are on Mac, as suggested by someone else in this thread use brew.
Firefox 47.0 stopped working with Webdriver.
Easiest solution is to switch to Firefox 47.0.1 and Webdriver 2.53.1. This combination again works. In fact, restoring Webdriver compatibility was the main reason behind the 47.0.1 release, according to https://www.mozilla.org/en-US/firefox/47.0.1/releasenotes/.
You can try using this code,
private WebDriver driver;
System.setProperty("webdriver.firefox.marionette","Your path to driver/geckodriver.exe");
driver = new FirefoxDriver();
I upgraded to selenium 3.0.0 and Firefox version is 49.0.1
You can download geckodriver.exe from https://github.com/mozilla/geckodriver/releases
Make sure you download zip file only, geckodriver-v0.11.1-win64.zip file or win32 one as per your system and extract it in a folder.
Put the path for that folder in the "Your path to driver" quotes.Don't forget to put geckodriver.exe in the path.
I eventually installed an additional old version of Firefox (used for testing only) to resolve this, besides my regular (secure, up to date) latest Firefox installation.
This requires webdriver to know where it can find the Firefox binary, which can be set through the webdriver.firefox.bin property.
What worked for me (mac, maven, /tmp/ff46 as installation folder) is:
mvn -Dwebdriver.firefox.bin=/tmp/ff46/Firefox.app/Contents/MacOS/firefox-bin verify
To install an old version of Firefox in a dedicated folder, create the folder, open Finder in that folder, download the Firefox dmg, and drag it to that Finder.
Here's what the problem looked like in Wireshark
Just load up 2.53.1 and every thing will work.
As of September 2016
Firefox 48.0 and selenium==2.53.6 work fine without any errors
To upgrade firefox on Ubuntu 14.04 only
sudo apt-get update
sudo apt-get upgrade firefox
It seems to me that the best solution is to update to Selenium 3.0.0, download geckodriver.exe and use Firefox 47 or higher.
I changed Firefox initialization to:
string geckoPathTest = Path.Combine(Environment.CurrentDirectory, "TestFiles\\geckodriver.exe");
string geckoPath = Path.Combine(Environment.CurrentDirectory, "geckodriver.exe");
File.Copy(geckoPathTest, geckoPath);
Environment.SetEnvironmentVariable("webdriver.gecko.driver", geckoPath);
_firefoxDriver = new FirefoxDriver();
I can confirm that selenium 2.53.6 works with firefox 44 for me on ubuntu 15.

ChromeDriver - Disable developer mode extensions pop up on Selenium WebDriver automation

I'm having the following issue:
When I'm running my automation tests, I keep getting the following alert "Disable Developer Mode Extension" in Chrome.
Is there a way to remove/disable this?. It is a blocker for me as it is making me fail some tests.
Thanks in advance
Did you try disabling the developer extensions with command line param?
Try with the following Selenium WebDriver java code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
I cannot disable extensions because I'm developing & testing one.
What I'm doing to dismiss this popup is the following:
I load chrome with my extension using Selenium.
I then immediately create a new window (via the SendKeys(Control-N) method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window.
I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds.
Then I close the tab via driver.Close(); (which also closes this new window). Chrome takes that as "cancel", dismissing the popup, leaving the original window and tab.
I find this necessary because the popup interferes with normal selenium browser interaction, like SendKeys, which I'm using to switch tabs and windows.
As of Chromedriver v2.33, the correct way to avoid this message is to pass load-extension to the excludeSwitches argument of the chromeOptions object. The following Java code should do the trick, although I haven't tested it, as I am running Python:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Collections.singletonList("load-extension"));
As others have pointed out, the culprit is probably the Chrome Automation Extension, which is loaded automatically by Chromedriver when it launches Chrome.
Chromedriver v2.33 introduced the new switch to prevent the extensions from being loaded:
Updates to excludeSwitches capability that now allows to exclude --load-extension switch.
I suspect that this solution does not require you to disable all extensions. You should still be able to manually load others.
This has been automatically fixed with a combination of ChromeDriver.exe V2.23 + Chrome 53.0.
To understand which chrome version will work with which driver, we can use the following well detailed doc: https://sites.google.com/a/chromium.org/chromedriver/downloads
Enjoy Automated Testing!!
I worked around this issue by using AutoIT.
First, you'll need to create the script.
closechromewarning.au3:
WinWaitActive("[CLASS:Chrome_WidgetWin_1]")
Send("{ESC}")
The script needs to be compiled to a .exe, then place the .exe in the path so it can be run.
Function that closes the warning, using c# syntax:
public void CloseChromeDialog()
{
System.Threading.Thread.Sleep(5000);
Process.Start(#".\closechromewarning.exe");
}
Sleep(4000) did work, but I upped it to Sleep(5000) just to be sure.
Calling CloseChromeDialog():
if(browser == chrome) //pseudo code
CloseChromeDialog();
resolved in chrome 54 and chromedriver 2.25
I too faced this problem. The solution is, if you are using maven then just add:
-Dchrome.switches=--disable-extensions
It will disable all the extensions and you will not face this problem.
I am using selenium Webdriver 2.53 and chrome version 56.0.2924.87 and the chrome driver.exe which I am using is 2.27. with this combination it is working with the
System.setProperty("webdriver.chrome.driver", "./utilities/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
DesiredCapabilities caps = new DesiredCapabilities().chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);
Try to add setProperty above ChromeDriver instance
System.setProperty("webdriver.chrome.driver","C:/[PATH]/chromedriver.exe");
driver = new ChromeDriver(capabilities);
pywinauto works
import pywinauto
window_title = "Disable Developer Mode Extensions"
app = pywinauto.Application().connect(name_re=window_title)
win_ext = app.window(name=window_title)
win_ext.close()
This is because one of your extensions is running in developer mode. Go through your extension list and disable extensions one-by-one until you find the culprit(s).

To run tests on different browsers using Selenium webdriver+ TestNG+Java

I am trying to run my tests using Selenium web driver + TestNG + Java, everything runs fine with Firefox, but when I tried to extend it to different browsers like IE and Chrome, I have included code for it, but it doesn't seem to work. I am using some excel files to pass input while automating it. Thanks in advance
Required Configuration with IE
1.The IEDriverServer exectuable must be downloaded and placed in your PATH.
2.On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
3.The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.
Check if java plugin is installed in your browser.
For more info go to http://code.google.com/p/selenium/wiki/InternetExplorerDriver
You cannot work with chrome/IE same as Firefox. In order to work with that you need chrome/IE driver, which is an executive file. The code for invoking the chrome and IE is a little different than Firefox.
For chrome you can take help from here
For IE you can take help from here
example for invoking driver
if(BrowserName.equalsIgnoreCase("Firefox")){
driver = new FirefoxDriver();
}else if(BrowserName.equalsIgnoreCase("Chrome")){
String ChromeDriverPath= "D:\\ChromeDriver\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", ChromeDriverPath);
driver=new ChromeDriver();
}else if(BrowserName.equalsIgnoreCase("IE")){
IEDriverPath32bit= "D:\\IEDriver\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", IEDriverPath32bit);

Categories