package com.qa.testBase;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;
public class TestBase {
public static AppiumDriver<MobileElement> driver;
private static final Logger log = Logger.getLogger(TestBase.class.getName());
@BeforeClass
public static void launchAppOnRealDevice() throws IOException {
PropertyConfigurator.configure("log4j.properties");
File appDir = new File("App");
File app = new File(appDir, "abc.apk");
// Set the Desired Capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "My Phone");
capabilities.setCapability(MobileCapabilityType.UDID, "52033054f4d3a397");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 6000);
capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
// capabilities.setCapability(AndroidMobileCapabilityType.NO_SIGN, true);
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, true);
capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "");
capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, OR.getProperty("APP_ACTIVITY_NAME"));
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
// Instantiate Appium Driver
try {
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
// Set the driver implicitlyWait candition
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Assert.assertNotNull(driver);
log.info("Driver : " + driver);
log.info("App installed successfully.");
} catch (MalformedURLException e) {
log.error(e.getMessage());
}
}
@Test
public void testOpenApp() {
log.info("Test Passed.");
}
@AfterTest
public void closeApp() {
driver.quit();
log.info("App closed successfully.");
}
}