I am writing a framework in JAVA using Appium, Selenium and Cucumber.
I start off by declaring an Appium Driver in one of my test step files and then this gets cast to an Android Driver or iOS Driver depending on the app under test.
I need some help please - I need all of my class files to have access to this instance of the driver but I’m not sure how to do this. The test is driven from the feature file and some of the test steps are in different class files so how can they all access this instance of the driver?
I want the driver to always be called driver as I don’t want to write separate code for IOS or Android…can I just cast the the initial AppiumDriver driver to AndroidDriver or iOSDriver?
I have tried protected AppiumDriver driver = null; but when I then try to access AppiumDriver from other classes (in other packages) it is not recognised.
If I used public static AppiumDriver driver = null;
I can then access driverfrom other classes by importing the class (called for example InitialiseDriver) and then using InitialiseDriver.driver
For info, the way I ended up doing this is creating a new class called FrameworkInitialize which declares and instantiates an AppiumDriver called driver.
public class FrameworkInitialize {
public static AppiumDriver driver = null;
}
I can then use driver in other classes by either extending the class:
public class MattsTestSteps extends FrameworkInitialize {
or if you can’t extend as the class is already extended, create a new instance of the driver which is a copy of the original driver as shown below:
Hi Aleksei,
It is not clear to me how can I achieve this.
I am working with Appium 2.0.0-beta.57, java-client 8.3.0, selenium-java 4.8.1.
Let me put an example:
AppiumDriver driver;
driver.context("NATIVE_APP"); -> error: cannot find symbol
((IOSDriver)driver).context("NATIVE_APP"); -> works
((AndroidDriver)driver).context("NATIVE_APP"); -> works
I would like to write the same code for the IOSDriver and AndroidDriver, not needing to downcast every time and duplicate code.
Before upgrading to java-client 8.X, I could just use an AppiumDriver instance.
Is there any way I could achieve this?