运行Appium测试时出现java.lang.ExceptionInInitializerError

时间:2018-12-06 07:50:03

标签: appium appium-android

运行Appium脚本时出现java.lang.ExceptionInInitializerError错误。我正在使用Page Factory。 使用Java客户端v6.1.0和Appium v​​1.9.1

错误:

render() {
    return (
      <View style={styles.container}>
        <FlatList
          data={this.state.arr}
          extraData={this.state}
          renderItem={({ item }) => <Text style={styles.item}>{item}</Text>}
        />
      </View>
    );
  }

自动化代码:

DriverSetup代码:

[RemoteTestNG] detected TestNG version 6.14.2
Dec 06, 2018 12:59:41 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: OSS
FAILED: Tests1
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 com.****.pages.MainScreen.<init>(MainScreen.java:25)
    at com.****.tests.smoke.Test.Tests1(Test.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:49)
    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
    at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329)
    at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
    at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
    at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
    at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
    at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
    ... 36 more


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

测试方法代码:

package com.****.utils;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import com.****.config.Config;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.appmanagement.ApplicationState;


public class DriverSetup{
    private Config config = new Config();
    private AndroidDriver<MobileElement> driver;

    public AndroidDriver<MobileElement> getDriver()
    {
        if (driver == null) {
            driver = initDriver();
        } else {
            driver.queryAppState(config.APP_PACKAGE);
            if (ApplicationState.NOT_RUNNING != null) {
                Activity activity = new Activity(config.APP_PACKAGE, "SplashActivity");
                activity.setAppWaitPackage(config.APP_PACKAGE);
                activity.setAppWaitActivity("SplashActivity");
                driver.startActivity(activity);
            } else if (ApplicationState.RUNNING_IN_BACKGROUND != null) {
                driver.launchApp();
            }
        }
        return driver;
    }

    public AndroidDriver<MobileElement> initDriver()
    {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("automationName", config.AUTOMATION_NAME);
        caps.setCapability("browserName", config.BROWSER_NAME);
        caps.setCapability("deviceName", config.DEVICE_NAME);
        caps.setCapability("platformName", config.PLATFORM_NAME);
        caps.setCapability("platformVersion", config.PLATFORM_VERSION);
        caps.setCapability("app", System.getProperty("user.dir") + config.APP_PATH);
        caps.setCapability("newCommandTimeout", config.NEW_COMMAND_TIMEOUT);
        caps.setCapability("autoAcceptAlerts", config.AUTO_ACCEPT_ALERTS);
        caps.setCapability("noReset", config.NO_RESET);
        caps.setCapability("autoGrantPermissions", config.AUTO_GRANT_PERMISSIONS);
        try {
            driver = new AndroidDriver<MobileElement>(new URL(config.APPIUM_SERVER_URL), caps);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return driver;
    }

}

页面对象类

package com.****.tests.smoke;

import org.testng.annotations.BeforeMethod;

import com.****.pages.MainScreen;
import com.****.utils.DriverSetup;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class Test {

    AndroidDriver<MobileElement> driver;

    @BeforeMethod
    public void setUp()
    {
        DriverSetup com = new DriverSetup();
        driver = com.getDriver();
    }

    @org.testng.annotations.Test
    public void Tests1() throws InterruptedException
    {
        MainScreen mainScreen = new MainScreen(driver);
        Thread.sleep(10000);
        mainScreen.allowAccessToUSBDevice();
    }

}

任何人都可以让我知道问题出在哪里吗?是代码,库还是工具?

预先感谢, 湿婆

0 个答案:

没有答案