How to start selenium with firefox driver - firefox

I try to follow this link: http://www.seleniumhq.org/docs/03_webdriver.jsp
In SetUpTest:
protected IWebDriver driver;
protected ISelenium selenium;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
selenium = new DefaultSelenium(
"localhost",
4444,
"*chrome",
"http://localhost");
selenium.Start();
verificationErrors = new StringBuilder();
}
When this line driver = new FirefoxDriver(); execute, I have this error:
Additional information: Cannot find a file named '***[Link to my project]\webdriver.xpi' or an embedded resource with the id 'WebDriver.FirefoxExt.zip'.
When I change it to driver = new ChromeDriver();, it opens firefox, but it cannot find element although element already render.
How to make selenium works with firefox?

If you was using C#, this appears that you have added Nuget packages of both Selenium .NET binding and Firefox Driver
I was following this tutorial https://learn.microsoft.com/en-us/vsts/build-release/test/continuous-test-selenium#create-the-test-project. It asks to add all these packages
After the project is created, you must add the Selenium and browser driver references used by the browser to execute the tests. Open the shortcut menu for the Unit Test project and choose Manage NuGet Packages. Add the following packages to your project:
Selenium.WebDriver
Selenium.WebDriver.ChromeDriver
Selenium.WebDriver.IEDriver
Selenium.Firefox.WebDriver
Selenium.WebDriver.PhantomJS.Xplatform
This is wrong. If you are using Firefox driver, you only need Selenium.WebDriver (maybe Selenium.Support as well) and Selenium.Firefox.WebDriver. You don't need Selenium.WebDriver.PhantomJS.Xplatform which will add the wrong WebDriver.dll into your project and the test run will complain about missing .json and .xpi file.

Related

Firefox 44.0.1 opening two tabs , when running selenium webdriver code

My Firefox recently got updated recently. My firefox version is 44.0.1. When I run a simple code as below in selenium webdriver, two tabs are opening in firefox. How can i get rid of the unwanted tab. I changed Firefox setting, but still two tabs are opening. one tab is a plain tab and the second tab is https://support.skype.com/en/faq/FA34612/what-is-the-skype-extension. How can I load my URL that I want to automate in a single firefox window. Do I need to change any firefox setting.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class Another {
#Test
public void tester(){
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://jqueryui.com/datepicker/");
}
}
Create a Firefox Profile and save it with name after making settings as per your requirement. Please call this profile in script.
Here is the steps to create firefox profile
Below is the script for example
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("CreatedProfile");
WebDriver driver = new FirefoxDriver(myprofile);
Thank You,
Murali

Second Instance of firefox browser is not opening in selenium

I am new to selenium. And I am trying to open multiple instances of firefox browser.
I am not using any Grid. And My selenium version is 2.47.1 and firefox version is 37.0.1.
Also, my browser is not closing automatically even I used quit()
Below is my code:
package TestAutomation;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestClassOpenBrowser {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
WebDriver d2 = new FirefoxDriver();
d2.get("http://yahoo.com");
d2.manage().window().maximize();
driver.quit();
d2.quit();
}
}
Keep in mind that version 2.42.0 was probably the last version of Selenium that really supported Firefox native events (for Firefox 31). Selenium 2.43 says it supports native events for Firefox32 but I don't think it really worked. In general, if you are running local Firefox instances, you want to be using Firefox 31 or Firefox31.0.6 , even if your on Selenium 2.47+ .
Also, if you are having trouble managing multiple driver instances, take a look at how I did it here (see the ShootoutSuiteTestBase.java
class) :
https://gist.github.com/djangofan/f5eda36f556fc55a5dcb
Tried with jar file version 2.45.0. it worked. Issue was in the latest jar files 2.47.1

Selenium Webdriver C# - Stop browser opening on program start up

I am writing a program for automation testing and it works fine. I do however have an issue with the amount of time it takes from the program to start up. This is down to the face that I initialize the IWebdriver = new firefoxDriver() in the public partial class so to allow for all functions to access the driver class with ease and no fuss.
So when i load the program the browser loads which takes maybe 15/20 seconds followed by the GUI I have built. Does anybody know a way of making the "driver" global but not initializing the browser until I call it in a function? i.e. I can load my program and fiddle with the variables etc and then when I am ready I click a button, then the browser loads and executes the function all without have the Iwebdriver = new firefox() in each function separately. Also the reason I have coded it this way (making it global) was due to different browser session issues. It would not see other browsers outside of the initial one on start up
Here is the basic code I am working with
public partial class Main : Form
{
IWebDriver driver = new FirefoxDriver();
public Main()
{
InitializeComponent();
}
}
Initialize it the same way but make it static:
Public static IWebDriver Driver;
And then set it to FirefoxDriver where you need it to open the browser:
Driver = new FirefoxDriver();

Get Firefox Profile Name at Runtime and Set preferrence

I have a scenario to handle where I am opening Firefox browser using Selenium Webdriver and each time it opens up a new profile. Code is written below:
WebDriver driver = new FirefoxDriver();
Each time it opens up a new profile which is something like : anonymous8958670169066009851webdriver-profile and profile name changes every time WebDriver opens up a Firefox browser. My intention is to get the profile name at runtime and set some preferences on it like handling unresponsive JS alert etc. Basically flow will look like something below:
WebDriver driver = new FirefoxDriver();
<Write some code here to get Firefox profile name>
<Set profile settings like **profile.setPreference("extensions.firebug.currentVersion", "1.8.1");>
Please help me in the second step i.e. Write some code here to get Firefox profile name if anyone already achieved something similar before.
You're approaching the problem backward. The correct thing to do is to create the FirefoxProfile object yourself, and using it in the constructor to the FirefoxDriver. The code would look something like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver driver = new FirefoxDriver(profile);

What profile does Selenium WebDriver use by default?

Where does Selenium WebDriver (a.k.a Selenium 2) get the anonymous profile that it uses when it opens FirefoxDriver? If it used the default for Firefox, %appdata%/roaming/mozilla/firefox/profiles, then if I were to disable a firefox plugin, it should be disabled for Selenium WebDriver also, so why isn't it?
I will answer it, supporting comment from #twall: When starting firefox in Selenium 2 WebDriver, it starts new, anonymous profile.
However, if you want to change it, you can create new Firefox profile and name it somehow, you know what it is - e.g. SELENIUM
Then in your code do this:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
That way, Firefox will always start that profile. In the profile you do all the settings you need
You can assign to each Selenium grid 2 node a specific firefox profile:
java -jar selenium-server-standalone-2.37.0.jar
-Dwebdriver.firefox.profile=my-profile -role node -hub http://example-server.org:4444/grid/register
Notice that the value of the webdriver.firefox.profile has to be the firefox profile name, not the location or the folder name
When running webdriver on a test server with no options to create profiles on the machine you can create your profile programmatically:
private FirefoxProfile GetFirefoxProfile()
{
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "http://localhost");
return firefoxProfile;
}
Fetching a profile is not useful as it is internally creating another copy of the fetched named profile. Accessing the original profile is required if
for eg: test coverage data should be written to a data store across multiple invocations.
Here is a possible solution by Overriding the ProfilesIni class of Selenium
Start by creating a Custom profile using firefox -p, say "CustomSeleniumProfile"
ProfilesIni profileini = new ProfilesIni() {
#Override
public FirefoxProfile getProfile(String profileName) {
File appData = locateAppDataDirectory(Platform.getCurrent());
Map<String, File> profiles = readProfiles(appData);
File profileDir = profiles.get(profileName);
if (profileDir == null)
return null;
return new FirefoxProfile(profileDir);
}
};
FirefoxProfile profile = profileini.getProfile("CustomSeleniumProfile");
//profile.setEnableNativeEvents(false);
driver = new FirefoxDriver(profile);
//ffDriver.manage().deleteAllCookies();
driver.get("http://www.google.com");

Resources