Mobile Testing automation with Selenium Webdriver using firefox browser as emulator

Mobile application testing sounds interesting J but when comes to automate the testing process for mobile application it is bit different to other applications, mobile applications generally need to be tested on different manufactures devices which raises the question – How to automate test cases which can be executed on different type of devices. The answer is quite simple.
Firefox supports the plugin -modify headers to emulate the behavior of any device. By using modify headers it can be simulated the behavior of any device .User can set the user agent to see the behavior of any device.
I have used the Selenium Webdriver to automate the test cases and utilize the modify headers plugin to simulate the device behavior on Firefox by passing headers like useragent and mobile number as per the application requirement.
Here is sample code snippet to implement it. The code is written in C# , you can implement in any language which supports selenium.
Below is the method which programmatically add the modify headers extension in the browser and set the properties of modify headers to simulate the behavior of device.
The method has two parameter useragent and mobile number which would be required to set the modify headers .I have created the firefox Profile instance and used the .AddExtension method to add the extension and used the SetPreference method to set the properties like useragent , mobilenumber and other minimum required properties for modifyheaders.
At the end passing the profile instance to webdriver firefox browser instance.you can set the headers based on your mobile application and can run the application in browser programmatically.

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
public IWebDriver OpenBrowserWithHeaders(string useragent, string mobilenumber)
{
FirefoxProfile profile = new FirefoxProfile();
if (File.Exists("modify_headers-0.7.1.1-fx.xpi"))
profile.AddExtension("modify_headers-0.7.1.1-fx.xpi");
else
Console.WriteLine("Modifyheaders.xpi file not found");
profile.SetPreference("modifyheaders.config.active", true);
profile.SetPreference("modifyheaders.config.alwaysOn", true);
profile.SetPreference("modifyheaders.headers.count", 2);
profile.SetPreference("modifyheaders.headers.action0", "Add");
profile.SetPreference("modifyheaders.headers.name0", "User-Agent");
profile.SetPreference("modifyheaders.headers.value0", useragent);
profile.SetPreference("modifyheaders.headers.enabled0", true);
profile.SetPreference("modifyheaders.headers.action1", "Add");
profile.SetPreference("modifyheaders.headers.name1", "x-up-subno");
profile.SetPreference("modifyheaders.headers.value1", mobilenumber);
profile.SetPreference("modifyheaders.headers.enabled1", true);
FirefoxDriver browser = new FirefoxDriver(profile);
return browser;
}
You can download the modifyheaders plug in from firefox addons and for details about selenium webdriver go to selenium website.
Best of luck for mobile automation!!

# Test Automation

Comments

Post a Comment

Popular posts from this blog

Hyundai i20 Bluetooth connectivity

How to take screenshot with Selenium Web driver using C#