Недавно я обновил свою зависимость maven от java-клиента appium для облегчения сенсорных функций.
Возникла ошибка ниже при запуске скрипта, который раньше выполнялся нормально.
java.lang.ExceptionInInitializerError
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:215)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:107)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at org.framework.adib.selendroidTestApp.pages.HomePage.<init>(HomePage.java:18)
at org.framework.adib.selendroidTestApp.StepDefinition.SelendroidTest.user_opens_Selendroid_application(SelendroidTest.java:39)
at ✽.Given User opens Selendroid application(src/test/java/org/framework/adib/selendroidTestApp/Feature/MyApplicationFeature.feature:5)
Определение POM
<!--https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>
Определение класса:
public class HomePage {
private AndroidDriver<AndroidElement> driver;
public HomePage(AndroidDriver<AndroidElement> driver) {
this.driver = driver;
try {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
} catch (Exception e) {
e.printStackTrace();
}
}
Любая помощь будет оценена.
Базовый класс для инициализации драйвера в базовом проекте:
`
private static AppiumDriver<MobileElement> androiddriver;
private static IOSDriver<IOSElement> iosdriver;
/**
* Gets the driver.
*
* @return the driver
*/
public static AppiumDriver<MobileElement> getAndroidDriver() {
return androiddriver;
}
/**
* Gets the driver.
*
* @return the driver
*/
public static IOSDriver<IOSElement> getIosDriver() {
return iosdriver;
}
private static AppiumDriverLocalService service;
private static AppiumServiceBuilder builder;
private static DesiredCapabilities cap;
/**
* Method to initialize the appium driver.
*
* @param: appURL
* location of the apk file
* @param: CONFIG
* Config properties of the application under test
*/
public static void openApplication(String appUrl, Properties config) throws MalformedURLException {
File appDir = new File(appUrl);
File app = new File(appDir, config.getProperty("APP_NAME"));
// defining appium url
String appiumUrl = "http://" + config.getProperty("APPIUM_IP") + ":" + config.getProperty("APPIUM_PORT")
+ "/wd/hub";
boolean isRunning = checkIfServerIsRunnning(config.getProperty("APPIUM_IP"),
Integer.parseInt(config.getProperty("APPIUM_PORT")));
if (!isRunning) {
startServer(config);
}
switch (config.getProperty("OS")) {
default:
// Log.info("OS version is not correct");
break;
case "ANDROID": {
// Defining APIUM Capabilities
DesiredCapabilities cap = new DesiredCapabilities();
// cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, config.getProperty("PLATFORM_VERSION"));
cap.setCapability(MobileCapabilityType.DEVICE_NAME, config.getProperty("EMU_NAME"));
cap.setCapability(MobileCapabilityType.BROWSER_NAME, config.getProperty("BROWSER_NAME"));
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, config.getProperty("APP_PACKAGE"));
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, config.getProperty("APP_ACTIVITY"));
cap.setCapability(MobileCapabilityType.FULL_RESET, false);
cap.setCapability(MobileCapabilityType.NO_RESET, true);
cap.setCapability(MobileCapabilityType.UDID, config.getProperty("EMU_NAME"));
// if(config.getProperty("IS_PHYSICAL").equalsIgnoreCase("FALSE"))
// {
// //To run with emulator
// cap.setCapability(MobileCapabilityType.u"avd",
// config.getProperty("EMU_NAME"));
//
// }
androiddriver = new AppiumDriver<MobileElement>(new URL(appiumUrl), cap);
// Implicit wait definition
androiddriver.manage().timeouts().implicitlyWait(Integer.parseInt(config.getProperty("TIME_OUT")),
TimeUnit.SECONDS);
System.out.println("The session ID for " + config.getProperty("EMU_NAME") + " is : " + ""
+ androiddriver.getSessionId());
break;
}`
Класс установки в тестовом проекте в тестовом проекте:
public static AppiumDriver<MobileElement> driver;
public static XlsReader XLR = null;
Scenario scenario = null;
public static Properties CONFIG;
static CommonFunctionAndroidImpl com_fun = null;
protected static String appUrl;
@Before
public void beforeMethod(Scenario scenario) throws Exception {
DOMConfigurator.configure("log4j.xml");
// getting instance of scenario
this.scenario = scenario;
Log.startTestCase(scenario.getName());
// Initialize Configurations
CONFIG = Config.initializeConfig();
// Initialize App location
appUrl = (System.getProperty("user.dir") + CONFIG.getProperty("APP_URL"));
Log.info("App location:" + appUrl);
// Initialize Appium Driver
BaseClass.openApplication(appUrl, CONFIG);
driver = BaseClass.getAndroidDriver();
// Initialize XCEL for Data
XLR = new XlsReader(System.getProperty("user.dir") + CONFIG.getProperty("DATA_FILE"));
// Initialize Common Function
com_fun = new CommonFunctionAndroidImpl(driver);
}`
Фактический класс испытаний:
CommonFunctionAndroidImpl com_fun = Setup.com_fun;
// Variables for accessing XLS methods
XlsReader XLR = Setup.XLR;
String name, userName, email, pwd, lang, adds;
int rowNum = 0;
HashMap<String, String> data = null;
// Page objects for all the application pages
protected HomePage hp;
protected static NewRegistrationPage rp;
protected static ConfirmRegistrationPage cp = null;
@Given("^User opens Selendroid application$")
public void user_opens_Selendroid_application() throws Throwable {
hp = new HomePage(Setup.driver);
}
@When("^User clicks on Create New User icon$")
public void user_clicks_on_Create_New_User_icon() throws Throwable {
rp = hp.clickNewRegBttn();
}
Класс домашней страницы:
private AppiumDriver<MobileElement> driver;
public HomePage(AppiumDriver<MobileElement> driver) {
this.driver = driver;
try {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
} catch (Exception e) {
e.printStackTrace();
}
}
@AndroidFindBy(id = "io.selendroid.testapp:id/startUserRegistration")
public WebElement newRegBttn;
@AndroidFindBy(id = "android:id/title")
public WebElement appTitle;
@AndroidFindBy(id = "io.selendroid.testapp:id/showToastButton")
public WebElement displayToast;
@AndroidFindBy(id = "io.selendroid.testapp:id/showPopupWindowButton")
public WebElement displayPopup;
public NewRegistrationPage clickNewRegBttn() {
newRegBttn.click();
return new NewRegistrationPage(driver);
}
public void clickDisplayToast() {
displayToast.click();
}
public void clickDisplayPopup() {
displayPopup.click();
}
public boolean appTitleTextDisplayed() {
return appTitle.isDisplayed();
}