Using Selenium on iPad? - selenium

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

Related

JMeter WebDriver Sampler - headless Firefox

Is it possible to run Firefox headless with WebDriver Sampler? I have used the "Use Chrome headless mode" option with Chrome before, but I don't see that option in Firefox Driver Config.
Perhaps this can be done in the actual sampler, by setting options to 'browser' in the code below?
WDS.sampleResult.sampleStart()
WDS.browser.get('http://jmeter-plugins.org')
WDS.sampleResult.sampleEnd()
Thank you.
There is no easy/GUI way of doing this using WebDriver Sampler (unless you patch FirefoxDriverConfig to include FirefoxBinary and pass to it --headless argument like:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
Another option would be switching to JSR223 Sampler to initialise the FirefoxDriver class yourself from the scratch.
More information: Firefox - Headless Mode
And last but not the least, if you're about to execute your Selenium tests on i.e. Linux machine which doesn't have GUI you can create a virtual display using Xvfb so Firefox would run attached to this virtual desktop. See Headless Execution of Selenium Tests in Jenkins for more details on implementing this on different operating systems.

Selenium grid to remote webdriver(chrome) hangs on get

I have a selenium grid with nodes on virtual machine. I can connect, open browser and close it but when i try navigating to a page it hangs on Executing: [get: http://google.com]
I use the latest verions of selenium, chromedriver and java.
Declaration:
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
driver = new RemoteWebDriver(new Uri(#"http://xxx.xx.xx.xxx:6000/wd/hub"), capabilities);
then i try to use it when i click a button on my win form:
driver.Navigate().GoToUrl("http://www.google.com");
I can see the node gets the command and logs Executing:[get:htttp://www.google.com] but just hangs. Url doesn't change in browser(its "data:," all the time )
I use windows 7 x64 and try to control browser on windows 7 x32. (if i connect to node on my pc the code works fine)
Any ideas?
Thanks!
I am seeing the exact issue with Safari (python). I am using selenium standalone server v2.47.1. My current workaround is to use JS:
"driver.execute_script("window.location.href = '{0}';".format(url))"
I also observed that if you don't set a homepage on Safari or have it default to load the homepage on new tab/window, the webdriver acts up and hangs on 'get' method.

How to get chromedriver working on android? java example?

I would like to be able to do testing using chromedriver on Android device. How is it possible?
I have rooted an Android device and cannot get the Chrome tests to work.
I tried to follow this guide: https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android
I cannot find which Chromedriver version I should install on Android device.
Does anyone have an example or step by step guide for this?
You don't need to install chromedriver on a phone, only your local machine you want to run tests from. I actually set this up couple weeks ago. This is basic set up you need:
public WebDriver getMobileChromeDriver() {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");
chromeOptions.setExperimentalOption("androidDeviceSerial", deviceId);
return new ChromeDriver(chromeOptions);
}
deviceId variable contains uuid taken from adb for particular device. If you don't provide it chromedriver will run on first available node.
One more thing you need to do before running tests is start adb server.
On linux based machines it would be something like:
adb start-server
(assuming you have adb in your path)
If you have problem with determining which chromedriver you need for your local machine let me know.
If you are using Windows machine you probably need to add one more line of code to point to your chrome binary:
System.setProperty("webdriver.chrome.driver", "<path_to_your_chrome_binary>");
For me, the previous answer works but with Chrome version 66 and chrome driver 37.
System.setProperty("webdriver.chrome.driver", "<path_to_your_chrome_binary>");
Even if system property is "webdriver.chrome.driver", you have to set the path of chrome on the device like "/data/app/com.android.chrome-1.apk"

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