appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 756 forks source link

Can't run any test. java.lang.ExceptionInInitializerError, Caused by: java.lang.IllegalArgumentException #1279

Open seregajoys opened 4 years ago

seregajoys commented 4 years ago

Every time when I try to run the android test(IOS doesn't try), the test failed with the following errors

java.lang.ExceptionInInitializerError
        at com.example.tests.test.CheckWorking.testCheck(CheckWorking.java:10)
Caused by: java.lang.IllegalArgumentException
        at com.example.tests.test.CheckWorking.testCheck(CheckWorking.java:10)

Environment

Appium Logs

Code To Reproduce Issue TestBase

public class TestBase {

    public static AppiumDriver driver;
    public static String loadPropertyFileAndroid = "Android.properties";
    public static String loadPropertyFileIOS = "properties/iOS.properties";
    protected static Example app;

    @BeforeSuite
    public void setUp() throws IOException {
        if (driver == null) {
            if (isIOS()) {
                CommonUtils.loadIOSConfigProp(loadPropertyFileIOS);
                CommonUtils.setIOSCapabilities();
                driver = CommonUtils.getIOSDriver();
                System.out.print("platform = " + driver.getPlatformName());
//                driver.resetApp();
//                if (driver.isAppInstalled("com.example.app")) {
//                    driver.removeApp("com.example.app");
//                }
            } else if (isAndroid()) {
                CommonUtils.loadAndroidConfigProp(loadPropertyFileAndroid);
                CommonUtils.setAndroidCapabilities();
                driver = CommonUtils.getAndroidDriver();

            }
        }
        if (app == null) {
            app = new Example(driver);
        }
    }

@AfterSuite
    public void clearCache(){
        driver.resetApp();
}

}

Capabilities

public static void loadAndroidConfigProp(String propertyFileName) throws IOException
    {
        FileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/src/main/resources/properties/" + propertyFileName);
        prop.load(fis);

        EXPLICIT_WAIT_TIME = Integer.parseInt(prop.getProperty("explicit.wait"));
        IMPLICIT_WAIT_TIME = Integer.parseInt(prop.getProperty("implicit.wait"));
        DEFAULT_WAIT_TIME = Integer.parseInt(prop.getProperty("default.wait"));
        APPLICATION_NAME = prop.getProperty("application.path");
        BASE_PKG = prop.getProperty("base.pkg");
        APP_ACTIVITY = prop.getProperty("application.activity");
        APPIUM_PORT = prop.getProperty("appium.server.port");
        AUTOMATION_INSTRUMENTATION_APPIUM=prop.getProperty("automation.instrumentation.appium");
        AUTOMATION_INSTRUMENTATION_SELENDROID=prop.getProperty("automation.instrumentation.selendroid");
        DEVICE_NAME=prop.getProperty("device.name");
        BROWSER_NAME=prop.getProperty("browser.name");
        PLATFORM_NAME=prop.getProperty("platform.name");
        PLATFORM_VERSION=prop.getProperty("platform.version");
        NEW_COMMAND_TIMEOUT=prop.getProperty("new.command.timeout");
        DEVICE_READY_TIMEOUT=prop.getProperty("device.ready.timeout");
        APPIUM_VERSION=prop.getProperty("appium.version");
        APP_WAIT_ACTIVITY=prop.getProperty("appWaitActivity");
    }

    public static void setAndroidCapabilities() {
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, BROWSER_NAME);
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, PLATFORM_VERSION);
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, DEVICE_NAME);
       capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,AUTOMATION_NAME);
        capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, NEW_COMMAND_TIMEOUT);
        capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
        capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, APPIUM_VERSION);
        capabilities.setCapability("appWaitActivity", APP_WAIT_ACTIVITY);
        capabilities.setCapability("appActivity", "com.soultime.app.ui.main.ActivityMain");
        capabilities.setCapability("autoGrantPermissions", true);
        capabilities.setCapability("recreateChromeDriverSessions", true);
        capabilities.setCapability("disableAndroidWatchers", true);
        capabilities.setCapability("autoGrantPermission", true);
        capabilities.setCapability("skipUnlock", true);
        capabilities.setCapability("allowTouchIdEnroll", true);
        capabilities.setCapability("unicodeKeyboard", true);
        capabilities.setCapability("resetKeyboard", true);
        capabilities.setCapability(MobileCapabilityType.APP, APPLICATION_NAME);
    }

    public static AppiumDriver getAndroidDriver() throws MalformedURLException {
        serverUrl = new URL("http://localhost:" + APPIUM_PORT + "/wd/hub");
        driver = new AndroidDriver(serverUrl, capabilities);
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        return driver;
    }
VictorS8 commented 3 years ago

If you still with this error, let me know which java version you are using on your IDE, because I was passing thought-out it and changing to java 1.8 on Intellij made work again

https://stackoverflow.com/questions/45718145/intellij-errorjava-java-lang-exceptionininitializererror/45718481

Kishorekumar2789 commented 2 years ago

I face this issue and this issue was fixed when I added Java JDK path in ecllipse under windows->preference-> installed jres. And selectthe checkbox of JDK.

Test executed successfully