Appium - RemoteWebDriver vs AppiumDriver initiation - selenium

What is the difference between initiating appium driver by using this
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
and
driver = new AppiumDriver(url, desiredCapabilities);
in terms of pre-requisites for initiating and the automation that they can handle or any other difference?

I have got the answer in this post.
Also , I came across a post , have a look at this . Its an excellent post about the selenium/webdriver architecture and its history which may clear a lot of doubts for some one looking for knowledge in this area. Specially in understanding how webdriver works internally end to end, from language binding command to return of the element.
EDIT: copy pasting from link above
RemoteWebDriver: This driver class comes directly from the upstream Selenium project. This is a pretty generic driver where initializing the driver means making network requests to a Selenium hub to start a driver session. Since Appium operates on the client-server model, Appium uses this to initialize a driver session. However, directly using the RemoteWebDriver is not recommended since there are other drivers available that offer additional features or convenience functions.
AppiumDriver: This driver class inherits from the RemoteWebDriver class, but it adds in additional functions that are useful in the context of a mobile automation test through the Appium server.
AndroidDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on Android devices through Appium. Only use this driver class if you want to start a test on an Android device or Android emulator.
IOSDriver: This driver class inherits from AppiumDriver, but it adds in additional functions that are useful in the context of a mobile automation test on iOS devices through Appium. Only use this driver class if you want to start a test on an iOS device or iOS emulator.
As you can see, the drivers and their names tie in closely with what they do. When it comes to initializing a driver, only use the Android or IOS drivers.

Related

Can I use Appium desktop to run test scripts?

Have gone through several Appium Desktop tutorial but all of them only showed how to manually test in the inspector window.
Does Appium desktop support automation test scripts? If so, how to send my tests written in node to it, or is there a handy npm package for the connection?
Thanks!
Finally connected webdriver to appium. Turns out webdriver can also be used for mobile testing.
Here are several points got me confused, hope it can help those who came into the same scene:
webdriver is not web exclusive - it can also be used for mobile e2e testing.
Appium server and Appium inspector do not necessarily work together. Once the server is started, it can be connected by an appium inspector or other services, e.g. webdriver.
Inspector is mostly for manual inspection. So far I haven't seen the possibility to supply automation test scripts to it.
And here's a complete walkthrough to those who're not familiar with Appium.

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 does Appium use platformName instead of platform

Selenium exposes a PLATFORM capability:
Appium's MobileCapabilityType extends Selenium's CapabilityType interface but instead of using the PLATFORM capability, it exposes PLATFORM_NAME:
Tried searching why this is the case but couldn't find any explanation. Does anyone here know the reason?
Well that's not used Nowadays PLATFORM_NAME was used till appium java-client 1.7. From 2.0 it's just used internally
From ReadME
AppiumDriver is now an abstract class, use IOSDriver and AndroidDriver
which both extend it. You no longer need to include the PLATFORM_NAME
desired capability since it's automatic for each class. Thanks to
#TikhomirovSergey for all their work
And for why, they were using Selenium's Platform in the first version 1.3 but then everything changed in the 1.4 where they decide to make their own capabilities with the future of Appium in their mind
This is to avoid the conflict of using MAC platform to test on iOS devices
Coz Selenium provided only ANDROID and MAC as platforms and though you want to test on ios devices which runs on iOS and you have to set MAC as platform [which will be odd right]
Now you can have Firefox as platformName as well
And Appium is a seperate entity from Selenium and they can't ask Selenium to add a Platform as IOS for them.So They created their own capability I guess.

Parallel execution using Selenium grid and test suites

I'm working on Selenium and I currently have a hub connected to two vms running linux with all the browsers.
I was able to launch the browsers . However, event hough I have two vms all my tests run on a single browser on a single vm. Selenium does not launch more than one browser in a vm. I have set maximum instance to 5 and it reflects in my gris console. I have testsuite which needs to run on linux and windows vm and it has to run simultaneously . Im using the WebDriver to call my grid like this .
capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://XXX.XXX.XXX.:4444/wd/hub"), capabilities);
And this is how I create my test Suite:
testNames.add(SupportPortalTestSuite.class.getName());
JUnitCore.main(testNames.toArray(new String[testNames.size()]));
Also when I register my nodes I get:
11:28:47.403 INFO - using the json request : {"class":"org.openqa.grid.common.RegistrationRequest","capabilities":[{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*googlechrome","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"Selenium","browserName":"*iexplore","maxInstances":1},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"firefox","maxInstances":5},{"platform":"LINUX","seleniumProtocol":"WebDriver","browserName":"chrome","maxInstances":5},{"platform":"WINDOWS","seleniumProtocol":"WebDriver","browserName":"internet explorer","maxInstances":1}],"configuration":{"port":5555,"register":true,"host":"10.235.132.161","proxy":"org.openqa.grid.selenium.proxy.DefaultRemoteProxy","maxSession":5,"hubHost":"10.235.1.50","role":"node","registerCycle":5000,"hub":"http://10.235.1.50:4444/grid/register","hubPort":4444,"url":"http://10.235.132.161:5555","remoteHost":"http://10.235.132.161:5555"}}
11:28:47.407 INFO - starting auto register thread. Will try to register every 5000 ms.
I need to run the tests on all available browsers on the vms simultaneously .
Selenium Grid give you the ability to run tests in parallel but doesn't handle it automatically. This is typically done with a test runner that handles it for you. Some frameworks like TestNG have this built-in but would likely need some customizing depending on your code.
Though it is preferred to use some frameworks such as testNG, you can run them with a plain java Threaded way too.

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