I have started learning appium recently, and I created some basic tests to launch an application, I referred a lot of guides and tutorials before creating the test scrips. Something I noticed was that different individuals has used different methods to create the driver. I tried using 3 methods that I picked up which I have mentioned below and all 3 methods are working. Im really confused on which method should I use when I'm writing test scrips in the future and is there any other method to create the driver.
Method 1
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
Method 2
WebDriver driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
Method 3
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
here are some of the guides that i used to create the test scripts and describing the different types of drivers available
http://www.automationtestinghub.com/first-appium-test-script/
If I create a driver in selenium I would be using the following syntax, which is the accepted method used when creating a driver for the test scripts
WebDriver driver = new ChromeDriver();
It would be great if someone could explain why different individuals use different methods instead when creating drivers in Appium and which is the best method for creating a driver for android automation scripts using java.
This all has to do with class inheritance.
WebDriver is a parent of AppiumDriver is a parent of AndroidDriver.
Each child has more and more specific code than its parent, but also includes all the code from its parent so eventually you want to build drivers of the exact type you want to get the specific code associated with them.
If you're certain you're only doing Android work, a base driver of AndroidDriver is going to be the most succinct. You can define this once and you're set.
If you're going to do iOS work as well, you will want your base driver to be an AppiumDriver so you can build iOS or AndroidDrivers in later code.
If you might need to do some web work, you will want your base driver to be a WebDriver so you can build drivers for all three platforms.
There is a good explanation of this at the main Appium forum.