automated.platforms.mobile.RunMobileDriver Maven / Gradle / Ivy
The newest version!
package automated.platforms.mobile;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import automated.platforms.mobile.android.ManageEmulator;
import automated.platforms.mobile.ios.ManageSimulator;
import automated.reporting.TestReporter;
import automated.platforms.mobile.android.ManageEmulator;
import automated.platforms.mobile.ios.ManageSimulator;
import automated.reporting.TestReporter;
import automated.test_manage.config.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;
import static automated.test_manage.config.Platform.*;
/**
* Created by Ismail on 1/5/2018.
* This Class contains methods related to manage MobileDriver
* to run, initialize and stop MobileDriver instance for Mobile applications
*/
public class RunMobileDriver {
/*************** Class Variables Section ***************/
// This variable is an AppiumDriverLocalService object to run appium Service
public static AppiumDriverLocalService appiumDriverLocalService = null;
// This variable is an AppiumServiceBuilder object to build appium service variants
public static AppiumServiceBuilder appiumServiceBuilder = null;
// This variable is a DesiredCapabilities object to assign custom capabilities for appium service
public static DesiredCapabilities desiredCapabilities = null;
/*************** Class Methods Section ***************/
// This method to run WebDriver as Mobile Application
// and open specific Simulator/Emulator for application
public static void setUp() {
// Start Appium server session
startAppiumServer();
// Check mobile case to run suitable device
// Create and Running mobile Simulators/Emulators
switch (Platform.mobile.toLowerCase()) {
case "android": {// If android case then
// Call launchAVD method from ManageEmulator class
// To run the AVD and get ready to run test cases
// Note: If Emulator isn't exist then first will
// create the Emulator then start it
ManageEmulator.launchAVD(Platform.virtualMobile);
break;
}
case "ios":
case "iphone": {// If iOS case then
// Call launchSimulator method from ManageSimulator class
// To run the Simulator and get ready to run test cases
// Note: If Simulator isn't exist then first will
// create the Simulator then start it
ManageSimulator.launchSimulator(Platform.virtualMobile);
break;
}
default: {// In case mobile value is wrong
// Write to report error and fail the test
TestReporter.error("Wrong Mobile Type" +
Platform.mobile + "\n it should be (android OR ios)", true);
}
}
}
// This method to close Simulator/Emulator
// then delete it and stop Appium server
public static void tearDown() {
// Check mobile value to delete Simulator/Emulator
// and close Appium
switch (Platform.mobile.toLowerCase()) {
case "android": {// If Android case then
// Call deleteAVD method from ManageEmulator class
// To delete created AVD
ManageEmulator.deleteAVD(Platform.virtualMobile);
break;
}
case "ios": {// If iOS case then
// Call deleteSimulator method from ManageSimulator class
// To delete created Simulator
ManageSimulator.deleteSimulator(Platform.virtualMobile);
break;
}
default: {// In case mobile value or something wrong
// Write to report error without fail the test
TestReporter.error("Wrong Mobile Type" +
Platform.mobile + "\n it should be " +
"(android OR ios)", false);
}
}
// Stop Appium server session
stopAppiumServer();
}
// This method to configure and run Appium server session
private static void startAppiumServer() {
/*************** Method Variables Section ***************/
// Define APPIUM IP ADDRESS to run the service
final String APPIUM_IP_ADDRESS = "127.0.0.1";
// Define APPIUM PORT to run service
int APPIUM_PORT = 4723;
// Build appium service variants
appiumServiceBuilder = new AppiumServiceBuilder();
// Assign IP Address for appiumServiceBuilder
appiumServiceBuilder.withIPAddress(APPIUM_IP_ADDRESS);
// Assign a free port for appiumServiceBuilder
appiumServiceBuilder.usingPort(APPIUM_PORT);
//Start Appium Local Service by initializing an object
// then assign appiumServiceBuilder param to object
appiumDriverLocalService = AppiumDriverLocalService.buildService(appiumServiceBuilder);
// Start appiumDriverLocalService
appiumDriverLocalService.start();
}
// This method to stop Appium server session
private static void stopAppiumServer() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy