How to set the capabilities to open the app or execute the test on the app using the real device ?
For that we can use UiAutomator2Options class or using DesiredCapabilities class
Steps:
Step1:
Need to set capabilities using the method setCapability () and need to give the values in the key value pair
Ex:
UiAutomator2Options cap = new UiAutomator2Options();
DesiredCapabilities cap = new DesiredCapabilities();
cap.SetCapability ("deviceName", "realme C33"); // Mobile name cap.setCapability("platformVersion", "13"); // Android version of your phone
cap.setCapability("app", "path of the Apk in your project");
Step2:
After setting the capabilities we need to give these details to the object of AndroidDriver
Android driver = new AndroidDriver(new URL("http://127.0.0.1:4723"),cap);
*****for the above code we need to manually start the appium server using the appium command from the cmd using the command “appium”*****
How to start appium server automatically before the test starts ?
To start the appium sever from the code (automatically) we have to use object of AppiumServiceBuilder class
Steps:
Step1:
create an object of AppiumServiceBuilder class and use the method withAppiumJS() and pass the path of the main.js file as the argument in the new file object
service = new AppiumServiceBuilder().withAppiumJS(new File("C://Users//Admin//AppData//Roaming//npm//node_modules//appium//build//lib//main.js"))
Step2:
give the ip address and port and build() the method.
service = new AppiumServiceBuilder().withAppiumJS(new File("C://Users//Admin//AppData//Roaming//npm//node_modules//appium//build//lib//main.js")).withIPAddress("127.0.0.1").usingPort(4723).build();
Step3:
use service.start() method to start the server and sevice.close() to close the server
*****use start() in beforemehtod annotation and sevice.close() in aftermethod annotation after driver.quit*****
Subscribe to my newsletter
Read articles from sumit singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by