Second Instance of firefox browser is not opening in selenium - firefox

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

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

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();

How to start selenium with firefox driver

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.

Clear Firefox cache in Selenium IDE

I'm using Selenium IDE to test a web application. Sometimes my tests succeed even though they should have failed. The reason is that the browser happens to load a previous version of a page from the cache instead of loading the newer version of that page. In other words, I might introduce a bug to my app without being aware of it because the tests may pass after loading a previous working version instead of loading the new buggy version.
The best solution I could have thought of is to delete the browser cache before running the tests. I have a Selenium script in which I run set-up selenium commands before running the tests. Is there a selenium command to clear Firefox cache? Alternatively, is there another way to prevent loading pages from the cache during the tests?
In python this should disable firefox cache:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.cache.disk.enable", False)
profile.set_preference("browser.cache.memory.enable", False)
profile.set_preference("browser.cache.offline.enable", False)
profile.set_preference("network.http.use-cache", False)
driver = webdriver.Firefox(profile)
hope this helps someone
You can disable the cache in firefox profile.
See this link for more details.
For those programming in Java, here is how I solve the issue:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.cache.disk.enable", false);
profile.setPreference("browser.cache.memory.enable", false);
profile.setPreference("browser.cache.offline.enable", false);
profile.setPreference("network.http.use-cache", false);
FirefoxOptions options = new FirefoxOptions().setProfile(profile);
driver = new FirefoxDriver(options);
Disclaimer: I've never had to do this before (clearing the cookies has always been sufficient for me), but from what I can see, this is functionality that is lacking in the current builds of Selenium, although from recent changelogs, it looks like the developers are making a push to make a standard way of doing this. In 2.33 of iedriverserver, They have the following changenote:
Introduced ability to clean browser cache before launching IE. This version
introduces the ie.ensureCleanSession capability, which will clear the
browser cache, history, and cookies before launching IE. When using this
capability, be aware that this clears the cache for all running instances of
Internet Explorer. Using this capability while attempting to run multiple
instances of the IE driver may cause unexpected behavior. Note this also
will cause a performance drop when launching the browser, as the driver will
wait for the cache clearing process to complete before actually launching
IE
http://selenium.googlecode.com/git/cpp/iedriverserver/CHANGELOG
To do this, you would specify this at driver creation time in the DesiredCapabilities Map using ensureCleanSession.
http://code.google.com/p/selenium/wiki/DesiredCapabilities
Since you're using firefox, it looks like you're out of luck in using a native way to do this. If you haven't tried driver.manage().deleteAllCookies();, I'd try that to see if it gets you where you need to be.
For C# and Geckodriver v0.31.0
public Task<WebDriver> newInstance()
{
return Task.Run(() =>
{
foreach (var process in Process.GetProcessesByName("geckodriver"))
{
process.Kill();
}
FirefoxProfileManager profilemanager = new FirefoxProfileManager();
System.Collections.ObjectModel.ReadOnlyCollection<String> profilesList = profilemanager.ExistingProfiles;
foreach (String profileFound in profilesList)
{
Console.WriteLine(profileFound);
}
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = profilemanager.GetProfile("default");
//profile = webdriver.FirefoxProfile()
profile.SetPreference("browser.cache.disk.enable", false);
profile.SetPreference("browser.cache.memory.enable", false);
profile.SetPreference("browser.cache.offline.enable", false);
profile.SetPreference("network.http.use-cache", false);
WebDriver driver = new FirefoxDriver(options);
return driver;
});
}

Selenium Webdriver and Firefox 18

My Selenium tests use onMouseOver features like
List<WebElement> menuitems = getDriver().findElements(By.tagName("li"));
Actions builder = new Actions(getDriver());
WebElement menu = menuitems.get(2);
getDriver().manage().timeouts().implicitlyWait(Constants.IMPLICITY_WAIT, TimeUnit.SECONDS);
builder.moveToElement(menu).build().perform();
I'm using Firefox driver. Since Firefox updated itself to version 18, my tests stopped working. I know this has to do with native events support - but does not version 18 support native events, or am i able to enable them? If not, is there any replacing implementation to my code?
I'm using selenium java 2.28.0.
For Firefox 18 support we need use selenium webdriver api 2.28.0,jar.
Selenium Java 2.27 mentions that native support for FF17 has been added. However, there has been no mention of support for FF18 in the change logs for 2.28. So its webdriver not supporting native events and not FF18 not supporting native events. You can try downgrading to FF 17 and probably turn off automatic updates for some time.
Rolling back to FF17 is a temporary work around until WebDriver version supports FF18
FF17 Extended Support Release packages -- http://www.mozilla.org/en-US/firefox/organizations/all.html
Note: If you are Mac user, you can simply rename your current FF from 'FireFox' to 'FireFox18' in your applications folder. Install the package from the above URL, which should create a new application called 'FireFox' that will be used by WebDriver.
My hover-over broke with v28. I now use the following hoverOver method with an optional javascript workaround and it seems to work okay.
public void HoverOver(IWebElement elem, bool javascriptWorkaround = true)
{
if (javascriptWorkaround)
{
String code = "var fireOnThis = arguments[0];"
+ "var evObj = document.createEvent('MouseEvents');"
+ "evObj.initEvent( 'mouseover', true, true );"
+ "fireOnThis.dispatchEvent(evObj);";
((IJavaScriptExecutor)driver).ExecuteScript(code, elem);
}
else
{
Actions builder = new Actions(driver);
builder.MoveToElement(elem).Build().Perform();
}
}
I was facing the same issue with Firefox 20. Then I re-installed latest Selenium server (.jar files).
http://selenium.googlecode.com/files/selenium-server-standalone-2.32.0.jar
Hope this works!

Resources