After a test fails, I need to go to the Appium server UI to stop and launch the server manually, to run the same test again.
Is there a better way? Am I missing something in testNG ?
public class CreateIssueTest extends TestUnitBaseAndroid {
@BeforeMethod
public void setUp() throws Exception {
doSetup();
driver = new SwipeableWebDriver(new URL(WEBDRIVER_URL), capabilities);
loginPage = PageFactory.initElements(driver, LoginPage.class);
feedPage = loginPage.testLogin(EMAIL, PASSWORD, SERVER);
}
@AfterClass
public void tearDown() {
}
@BeforeTest
public void beforeTest() {
}
@AfterTest
public void afterTest() throws IOException {
// doAfterTest();
}
@AfterMethod
public void afterMethod() throws IOException {
doAfterMethod();
doTeardown();
}
public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {
private RemoteTouchScreen touch;
public SwipeableWebDriver(URL remoteAddress,
Capabilities desiredCapabilities) {
super(remoteAddress, desiredCapabilities);
touch = new RemoteTouchScreen(getExecuteMethod());
}
public TouchScreen getTouch() {
return touch;
}
}
public class TestUnitBaseAndroid extends TestUtils{
public TestUnitBaseAndroid() {
log = LoggerUtils.getLogger();
log.info("log4j initialized");
}
public static volatile WebDriver driver;
//public static AndroidDriver driver;
public static DesiredCapabilities capabilities;
public static final String WEBDRIVER_URL = "http://127.0.0.1:4723/wd/hub";
public static String baseUrl;
public static Logger log;
public static LoginPage loginPage;
public static NavMenuPage navMenuPage;
public static FeedPage feedPage;
public static IssuesPage issuesPage;
public static FollowingPage followingPage;
public static SupplierPage supplierPage;
public static AboutPage aboutPage;
public static SettingsPage settingsPage;
public static LogoutPage logoutPage;
public static CreateIssuePage createIssuePage;
public static final String APP_PATH = "/Users/username/UserFiles/dev/apks/";
public static final String RESOURCES_PATH = "src/test/java/com/mycompany/qe/clients/resources/";
public static final String loginPagePropertiesFile = RESOURCES_PATH + "loginPageAndroid.properties";
public static String USERNAME = null;
public static String PASSWORD = null;
public static String SERVER = null;
public static String EMAIL = null;
public static void doSetup() {
Properties properties = PropertyUtils.getProperties(loginPagePropertiesFile);
USERNAME = properties.getProperty("username");
PASSWORD = properties.getProperty("password");
SERVER = properties.getProperty("server_android");
EMAIL = properties.getProperty("email");
capabilities = new DesiredCapabilities();
// File appDir = new File(System.getProperty("user.dir"), "");
File app = new File(APP_PATH, "appExposure-adhoc.apk");
capabilities.setCapability("deviceName", "Nexus_5_API_21");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
}
public static void doTeardown() {
driver.quit(); // poof
}
public static void doAfterTest() {
String msg = "All tests completed";
Reporter.log(msg);
log.info(msg);
}
public static void doAfterMethod() {
String msg = "Test completed";
Reporter.log(msg);
log.info(msg);
}