Selenium: how to set mobile mode on Firefox Driver - selenium

I have worked on Selenium Firefox Driver with Java
I was seach for set mobile mode. but it just Code for ChromeDriver.
I know we will FirefoxProfile but i'm not clarify code on java so
How can i setup Mobile mode for FirfoxDriver.
Thanks

of course most resource for chrome driver
so test it
it worked for me
firefox_options.set_capability("deviceName", "iPhone")
and if you like to give user agent , this can help you
firefox_profile.set_preference("general.useragent.override", user_agent)
as you can see this code for python if you use java maby this link helpful for that
https://stqatools.com/selenium-desired-capability-marionette/

See if this works for you.
fprofile.setPreference("general.useragent.override", "iPhone");
Or you can try what is mentioned in the other question - How to use webdriver mobile web on desktop browser

Related

How to run chrome driver in headless mode or in background

I've been using chrome driver (with selenium webdriver), so far it never caused any issue, now for some requirement i want to run test cases in background. How can I do this?
Currently Chrome 59 supports headless mode.
You just need to use those chromeOptions to use headless chrome in selenium.
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("--disable-gpu");
You can refer below link for more details:
https://www.automation99.com/2017/07/how-to-use-chrome-headless-using.html
According to this post Any way to start Google Chrome in headless mode?, a new flag --headless is available in Chromium but Selenium is still to catch up as far as my limited googling skills tell me.
In the mean time you can explore HTMLUnitDriver for headless testing.
WebDriver driver = new HtmlUnitDriver((BrowserVersion.CHROME), true);

Using Selenium on iPad?

I use a selenium application, and I make test on my computers browsers. It opens and manage the browsers.
Would there be a way to simulate an iPad and run this same code on it? Same thing for a cellphone?
So far I found people who wrote they did so by emulation but did not say how...
I execute iPad testing via emulation using ChromeDriver. Does this help? With C#:
IWebDriver driver;
ChromeOptions ipadOptions = new ChromeOptions();
string deviceName = "Apple iPad";
ipadOptions.EnableMobileEmulation(deviceName);
driver = new ChromeDriver(ipadOptions);
My biggest struggle was testing requirements depending on orientation (landscape vs. portrait.) It doesn't support switching orientation which is ridiculous.
To be able to use selenium code with Android device browser, try following:
install Android SDK on your computer to get access to Android Debug Bridge (adb) features
start adb server from cmd/Terminal with "adb start-server" command
(target device should be already connected)
start in the same way chromedriver server with "chromedriver" command (chromedriver executable should be already in your system Path)
you should see something like:
Starting ChromeDriver 2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3) on port 9515(in my case it always starts on 9515 port, but you have to check this value to use it in next step)
run code with 'androidPackage':com.android.chrome' chromeOptions and instance of remote webdriver. Python code looks like:
from selenium import webdriver
capabilities = {'chromeOptions': {'androidPackage':com.android.chrome',}}
driver = webdriver.Remote('http://localhost:9515', capabilities) # 9515 is mentioned port number on which chromedriver server started
driver.get('http://google.com')
driver.quit()
P.S. It's not a direct answer on question how to use selenium with iPad, but OP asks for selenium + Android also

Why do we need IEDriver and ChromeDriver but no Firefox Driver?

I have small doubt.
Why do we need IEdriver and Chrome Driver running selenium scrits in IE and Chrome but we do not need a firefox driver to run the script?
Is there any reason for the same?
This is because of the Native Browser approach used in WebDriver.
Each and every browser uses different JS Engine.
All drivers [Chrome Driver, IE driver, etc.,] are built based on the special JS Engine used by each browser.
Selenium offers inbuilt driver for Firefox but not for other browsers. [Not sure it may happen in future, since TestNG and JUnit library files are a part of Selenium-standalone-server right now]
Straight from a google search for FirefoxDriver, the official documentation states:
Firefox driver is included in the selenium-server-stanalone.jar available in the downloads. The driver comes in the form of an xpi (firefox extension) which is added to the firefox profile when you start a new instance of FirefoxDriver.
External drivers are the preferred process by the Selenium developers. They allow the driver versioning to be tied more closely to the browser than to Selenium, and they can be supported by the browser authors (e.g., ChromeDriver, OperaDriver). There is a long-standing plan to replace FirefoxDriver with a Mozilla-supported driver based on Mozilla's "Marionette" architecture.
Firefox driver is already included in the selenium-server-standalone.jar package.

how to use different version of firefox using webdriver?

how to set Firefox version in web-driver?
I just want to user different version of Firefox.
like different version 19, 20 , 21....
please provide a generic solution which help for other browser also.
You have to install all the versions on your system. Then you can use the System property webdriver.firefox.bin to define the path for Firefox. Note than since the path is set through a System property, you will not be able to run two different Firefox in the same Java process.
This solution is specific to Firefox. There is no generic solution. You have to configure every WebDriver yourself.
More information about the configuration of Firefox Web Drvier.
Finally i have found solution to run with different browser version
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox-2.app/Contents/MacOS/firefox-bin");
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
System.out.println(driver.getTitle());
driver.close();
driver.quit();
I have found how to start a different FireFox browser (actually WaterFox) in Python Selenium, replacing
driver = webdriver.Firefox()
with
driver = webdriver.Firefox(firefox_binary = "/path/to/my/waterfox")
(Ubuntu 20.04, Python 3.95)

Selenium difference on windows / linux

I have a JUnit test that imports org.openqa.selenium.interactions.Actions.
Specifically, I am using dragAndDrop, outlined here
When I run the Junit test on my local machine (windows), it runs perfectly. However, when the same test is run on a Linux machine, the method does not work. Everything else in the test runs fine but the dragAndDrop method does not work.
A co-worker said that it might have something to do "XVFB" but could not elaborate much.
Any comments appreciated, thanks!
I am assuming you are using Firefox on Linux? Native events are disabled by default for Firefox on Linux. Advanced Actions API need native events. Try enabling them and then check your test on linux like below,
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);