Palak Shah
Well-known member
- Joined
- Apr 29, 2020
- Messages
- 97
- Programming Experience
- 1-3
Hello,
I want to run my tests in mobile mode of firefox browser, but I am facing difficulties in that, I have done similar thing for chrome mobile mode and it is working but not in case of firefox,
Can anyone help?
I want to run my tests in mobile mode of firefox browser, but I am facing difficulties in that, I have done similar thing for chrome mobile mode and it is working but not in case of firefox,
Can anyone help?
Firefox code (temporary solution:
private static IWebDriver GetFireFoxDriver(string userAgent)
{
var rand = new Random();
var firefox_options = new FirefoxOptions();
firefox_options.AddArgument("-private");
firefox_options.AddArguments("--window-size=1024,768");
firefox_options.AddArguments("--window-position=0,0");
firefox_options.AddArgument($"--user-agent= {userAgent}");
firefox_options.AddArgument("--disable-backgrounding-occluded-windows");
var driver = new FirefoxDriver("C:\\selenium\\firefoxdriver", firefox_options, TimeSpan.FromMinutes(3));
if (userAgent.Contains("Mobile") == true)
{
driver.Manage().Window.Size = new Size(411, 731);
}
return driver;
}
Chrome code:
private static IWebDriver GetChromeDriver(string userAgent)
{
var options = new ChromeOptions();
options.AddArgument("incognito");
options.AddArguments("disable-infobars");
//Session 0 limit - 1024 x 768
options.AddArguments("--window-size=1024,768");
options.AddArguments("--window-position=0,0");
options.AddArgument($"--user-agent= {userAgent}");
if (userAgent.Contains("Mobile") == true)
{
// Commenting "EnableMobileEmulation" with Device Name - as it overrides the set Driver's userAgent value
// Added Device Settings to pass userAgent and explicit values of Mobile Device - To avoid captcha block
var settings = new ChromeMobileEmulationDeviceSettings(userAgent)
{
Height = 731,
Width = 411,
PixelRatio = 2.6
};
options.EnableMobileEmulation(settings);
//options.EnableMobileEmulation("Pixel 2");
}
options.AddArgument("--disable-backgrounding-occluded-windows");
//options.BinaryLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe";
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;
var driver = new ChromeDriver(service, options, TimeSpan.FromMinutes(3));
return driver;
}