Selenium difference on windows / linux - selenium

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

Related

Running Selenium via jenkins on VM, screen size

I have a problem with running Selenium tests on VM.
Tests are written under 1920x1080 resolution everything is OK until I run tests manually. Tests passes. The problem appear when I run tests through Jenkins. It's not a problem in my code.
I dont know why but screen resolution is much lower (1032, 776) - actually it's browser size. And that is the cause why buttons to test are not visible. Tests fails.
Jenkins is opening by "Run slave agent via Java Web Start" and evertyhing works automatically on windows serwer. Old Selenium tests (written under lower resolution) works perfect. So the problem is closely related to screen size.
Thank you in advance.
If you are working on Windows the following should work:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1920,1080");
System.setProperty("webdriver.chrome.driver","\\path\\chromedriver.exe");
driver = new ChromeDriver(options);

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

Selenium: how to set mobile mode on Firefox Driver

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

How to run the selenium code on linux using firefox without GUI?

I had redhat Linux server command line but there is no GUI for that and I need to run selenium code on this server with firefox. As I am new to selenium so I am not sure whether it will work or not.
For achieving this I had install Firefox on my Redhat linux machine successfully but not able to trigger that as it is showing no display found.
Is there any other way to achieve this for headless browsing, where virtually a firefox will be opened and selenium code can be executed without GUI. Is it possible to do??
You can use HtmlUnitDriver of selenium to use headless browsing but it will not open firefox and may be not loading all content to it's cache as same as firefox
Refer Below:-
https://code.google.com/p/selenium/wiki/HtmlUnitDriver
Another thing you can use is Phantomjs with selenium Webdriver. This is most using pattern by industries for headless browsing
Refer below:-
http://www.guru99.com/selenium-with-htmlunit-driver-phantomjs.html
Yes you can trigger selenium file using command line
http://www.tutorialspoint.com/testng/testng_executing_tests.htm
Bash file is running fine in windows for testng but it is not working in linux/mac
Now if still your firefox is not opening then it is basically issue of some setting with your OS with firefox
Refer that too :-
https://serverfault.com/questions/279036/open-terminal-via-ssh-run-firefox-display-not-found
May be you have problem with some permission in red hat
Hope it will help you :)

Setting up Selenium for recording as well as running in different browsers and platforms

I'd like to setup a Selenium server so that clients can record tests locally, recorded tests can be replayed and tested on an Ubuntu server with Firefox + Chrome.
Unfortunately the Selenium site is so confusing and mentions so many different projects (Selenium 1, Selenium 2, Selenium RC, Selenium Grid) that I'm not sure where to start.
How do I go about setting up Selenium Server on an Ubuntu box?
Unfortunately the Selenium site is so
confusing and mentions so many
different projects (Selenium 1,
Selenium 2, Selenium RC, Selenium
Grid) that I'm not sure where to
start.
Selenium has multiple versions
IDE - mainly to record the test and play it back. It is mainly a Firefox Addon. This can be used for very basic testing. You can also export the recorded test to selenium RC. All these mentioned in seleniumhq.org->documentation section: http://docs.seleniumhq.org/docs/
RC - Like any other automation tool, you can write your own code to run the test rather than just recording and playing it back. This has far better capabilities than IDE including support for several languages (Java, Javascript, Ruby, PHP, Python, Perl and C#) and support for almost every browser out there in various platform.
Grid - This helps in running multiple tests in parallel.
To record and run the test in Firefox (NOT CHROME) its very easy. This doesn't require a selenium server running.
record the whole test
save it in a file
Copy the file to Ubuntu machine
Open the same test using IDE in Ubuntu machine and run it again in firefox
If you want to run on chrome, then you need to go to the next level of using selenium RC. And this requires the selenium server running.
How do I go about setting up Selenium
Server on an Ubuntu box
Download selenium-server jar from here. Copy this to any directory in your ubuntu server
Open a terminal and navigate to the folder which has the selenium server jar.
Enter java -jar selenium-server-jarfilename.jar
Selenium server will start on port 4444 by default and keep listening to the tests.
The site is confusing in terms of the versioning and names. Selenium is the name of the entire project which started off as Selenium RC (remote control). Selenium RC is the old version of the API which is also sometimes called Selenium 1. Selenium 2 is the newest version and the latest release was last week being Selenium RC2 (release candidate). This uses a different API to Selenium RC. The new API is known as WebDriver. The new API still allows you to access the older Selenium RC but only for backwards compatibility.
Since you're starting now, there is no reason for you to use the Selenium RC API. You should instead use the advanced user interactions which are part of WebDriver. Setting up WebDriver is pretty easy and there is a decent guide on it here. You should note that the API used there is the older standard (2.0 beta) which uses WebElements. The new API (advanced user interactions) decouples actions from the elements they are performed on a lot more. I would recommend you use the latest versions of the API which is being actively supported rather than older deprecated versions.
Since you want to do this all locally, the second link I gave you should be enough to get you up and running. Assuming you're going to be using the Java bindings it is as simple as:
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
Actions builder = new Actions( driver );
builder.sendKeys( driver.findElement( By.name("q") ), "Cheese!" );
Action action = builder.build();
action.perform();
//Close the browser
driver.quit();
}
}
This is the example code edited to use advanced user interactions.
You must have two things to write and execute selenium tests.
1) Selenium Server is also known as Selenium RC (Remote Control). You can go to this link and download Selenium Server.
You can start selenium server with command java -jar ur_selenium_server.jar
2) Client Driver: Using client-driver you can code selenium tests. It consists of combination of selenium commands that perform certain actions on the UI. For e.g. click, select etc.
Selenium supports many different language bindings for client-driver. Download appropriate client-driver for your preferred language from above download page.
You can refer client driver apis and code your tests.
Hope this helps