Selenium Webdriver with multiple browser versions

2,270 views
Skip to first unread message

Treighton

unread,
Jun 9, 2011, 8:16:21 PM6/9/11
to Selenium Users
Hi. New user. I'm writing tests with the latest release of Webdriver.
My tests are in C# and are executing as unit tests in the Visual
Studio 2008 IDE. A typical test would look like this:
[TestMethod]
public void NavigateToValidationPageFromHome_UseFirefox()
{
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:2446/default.aspx");
// navigate to validation page by clicking 'Validation' link on
homepage
IWebElement elem = driver.FindElement(By.LinkText("Validation"));
elem.Click();
driver.Quit();
Assert.AreEqual(driver.Title, "Validation Examples");
}

My question: if I have multiple versions of browsers installed on the
test machine for, eg. Firefox, can I write tests to run on each
version: That is, can I have a method
NavigateToValidationPageFromHome_UseFirefoxVersion3,
NavigateToValidationPageFromHome_UseFirefoxVersion4, etc? I've been
unable to find any options or settings for WebDriver code for multiple
versions of browsers, but this seems a pretty essential kind of web
testing, so it's hard to believe it isn't possible.

Brad

unread,
Jun 10, 2011, 6:08:16 PM6/10/11
to Selenium Users
I would recommend setting up a Selenium Grid for this. With Grid, you
can set up your hub and remote webdriver client locally on the same
machine, just use different ports. With each client, you can set
specific capabilities (i.e. browser, version, platform).

You can set browser and version in a DesiredCapabilities object. Then,
pass this in to a RemoteWebDriver.
I'm using Java, but the bindings are fairly similar:

DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setVersion(version);
RemoteWebDriver driver = new RemoteWebDriver ( new URL(gridUrl), dc );

Hope this helps!
-Brad

QA Automation at nixsolutions.com

unread,
Jun 10, 2011, 12:14:28 PM6/10/11
to Selenium Users
I hope this help.

QA Automation at nixsolutions.com

unread,
Jun 10, 2011, 12:11:59 PM6/10/11
to Selenium Users
Hi,

to resolve this issue you will have to create one simple additional
method which will be switching current version of FF 4 to FF 3 and
back.
This is should be something like that:
using using Microsoft.Win32;

...

public void SwitchFF(bool is4)
{
RegistryKey currentFFVersion =
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Mozilla\Mozilla Firefox",
true);
if (currentFFVersion != null)
{
if (is4)
currentFFVersion.SetValue("CurrentVersion", "4.0.1
(en-US)");
else
currentFFVersion.SetValue("CurrentVersion",
"3.6.17 (en-GB)");
}

}

and then if you need to use Firefox 4 call SwitchFF(true);

for example:

[TestMethod]
public void NavigateToValidationPage()
{
SwitchFF(true);
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:2446/default.aspx");
// navigate to validation page by clicking 'Validation' link on
homepage
IWebElement elem = driver.FindElement(By.LinkText("Validation"));
elem.Click();
driver.Quit();
Assert.AreEqual(driver.Title, "Validation Examples");
}

this will run test against ff4.


Note: to make sure which FF versions are installed on you machine,
just go to HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox

Let me know if you have any questions.


____________________________
nixsolutions

On Jun 10, 3:16 am, Treighton <ree.em...@gmail.com> wrote:

Jim Evans

unread,
Jun 13, 2011, 7:01:09 AM6/13/11
to Selenium Users
Note that this code is likely to fail on Windows Vista and Windows 7
unless you elevate your permissions first or disable UAC, since
without elevation, you do not have permissions to write to the
HKEY_LOCAL_MACHINE hive of the registry. A better solution, if you're
using C# is to create a FirefoxBinary object and point to the
different executable files. Your code would look something like this:

FirefoxBinary binary = new FirefoxBinary("C:\path\to\firefox.exe");
FirefoxProfile profile = new FirefoxProfile();
IWebDriver driver = new FirefoxDriver(binary, profile);


On Jun 10, 12:11 pm, "QA Automation at nixsolutions.com"
> > testing, so it's hard to believe it isn't possible.- Hide quoted text -
>
> - Show quoted text -

Mark Collin

unread,
Jun 13, 2011, 7:02:34 AM6/13/11
to seleniu...@googlegroups.com
Um hacking the registry on the fly is a simple solution...

You could just specify the location of the firefox binary when you create
your driver object...

Hi,

...

}

for example:


____________________________
nixsolutions

--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Reply all
Reply to author
Forward
0 new messages