Appium 运行 testng 报错,请前辈指教

云飞凌风 · 2014年09月16日 · 最后由 云飞凌风 回复于 2014年09月16日 · 3804 次阅读

下面是部分 java 代码

protected ImplementationScreen impScreen;
protected String methodName;

@BeforeClass(alwaysRun = true)
@Parameters(value = { "deviceName", "platformName", "platformVersion", })
public void setup(String deviceName, String platformName, String platformVersion) {
    TestNgParameters tngparam = new TestNgParameters();
    tngparam.getDeviceName().put("deviceName", deviceName);
    tngparam.getPlatformName().put("platformName", platformName);
    tngparam.getPlatformVersion().put("platformVersion", platformVersion);  
    impScreen = new ImplementationScreen(tngparam);

}

下面是报错信息:

[TestNG] Running:
  /private/var/folders/8q/c2df2pbx7klbysvszjxxbj580000gn/T/testng-eclipse-2043619497/testng-customsuite.xml

FAILED CONFIGURATION: @BeforeClass setup
org.testng.TestNGException: 
Parameter 'deviceName' is required by @Configuration on method setup but has not been marked @Optional or defined
in /private/var/folders/8q/c2df2pbx7klbysvszjxxbj580000gn/T/testng-eclipse-2043619497/testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:358)
    at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

提示的主要错误是:该如何处理?请前辈指教、谢谢

Parameter 'deviceName' is required by @Configuration on method setup but has not been marked 
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 26 条回复 时间 点赞

你的配置信息都没写啊

#1 楼 @cy_suncheng 这配置信息在哪里配置,请高手指教,我是新手,不知道如何配置呢。

#1 楼 @cy_suncheng
你看我这里是已经配置了么?

#3 楼 @wangcityboy deviceName 和 device 一样么?

#4 楼 @lihuazhang 哦,之前是 device 的,后来我把所有的 device 换了 deviceName 这个我之后换了名称,跟这个没关系。

#3 楼 @wangcityboy 如果没看错的话,你 run 的 xml 不是你截图里的 xml。。。。

#6 楼 @cy_suncheng 是的啊,你眼里真好。。你直接看截图就好了,都是一样的问题。。

#7 楼 @wangcityboy 你 run 带参数的 xml 也报错么?

#8 楼 @cy_suncheng 不是 run 带参数的 xml,我是 run 截图中的 AndroidTest.java 时报错的,这个是 JUnit 测试入口

#9 楼 @wangcityboy 你不是用的 testNG 么? 直接 run xml 就行了

@Parameters(value = { "deviceName", "platformName", "platformVersion", }) 如果是 testNG 不用加 value =

#11 楼 @cy_suncheng 现在可以了,不过运行后,为什么不启动模拟器啊,看日志,提示已经执行成功了。

下面为其中的一个方法

@Test
public void testLogin() {
    System.out.println("Executing Login Scenario");
    methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
    try {
        impScreen.login(methodName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

下面为运行日志

[TestRunner] Running the tests in 'iPhoneHybEshopTest' with parallel mode:tests
[RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@1c53fd30 priority: 10
[TestClass] Creating TestClass for [ClassImpl class=com.photon.phresco.testcases.iPhoneEshopTest]
[TestNG] Running:
  /Users/yunfeiyang/快盘/Example/JavaCode/functional/src/test/resources/testsuite/testsuite.xml

[SuiteRunner] Created 1 TestRunners
[ThreadUtil] Starting executor timeOut:2147483647ms workers:1 threadPoolSize:5
[TestRunner] Running test iPhoneHybEshopTest on 1  classes,  included groups:[] excluded groups:[]
===== Test class
com.photon.phresco.testcases.iPhoneEshopTest
  @BeforeClass iPhoneEshopTest.setup(java.lang.String, java.lang.String, java.lang.String)[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testuserRegister()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForMobilePhone()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForCameras()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForAudioDevice()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testcheckOutScenario()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForComputer()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForMP3Players()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testLogin()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForMovieAndMusic()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForTablets()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testspecialOffers()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForVideoGames()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForTV()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
    @Test iPhoneEshopTest.testAddToCartForAccessories()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
  @AfterClass iPhoneEshopTest.tearDown()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
======
[Invoker 614877437] Invoking @BeforeClass iPhoneEshopTest.setup(java.lang.String, java.lang.String, java.lang.String)[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
九月 16, 2014 2:44:05 上午 AbstractBaseScreen launchDriver
信息: EXCEPTION IN LAUNCHDRIVER No enum constant com.photon.phresco.enumscreen.LoadXmlParser.IPHONE SIMULATOR
[Invoker 614877437] Invoking com.photon.phresco.testcases.iPhoneEshopTest.testLogin
Executing Login Scenario
九月 16, 2014 2:44:05 上午 AbstractBaseScreen waitForGivenTime
信息: ENTERING WAIT FOR GIVEN TIME
九月 16, 2014 2:44:08 上午 ImplementationScreen login
信息: EXCEPTION IN LOGIN null
[Invoker 614877437] Invoking com.photon.phresco.testcases.iPhoneEshopTest.testAddToCartForTV
九月 16, 2014 2:44:08 上午 AbstractBaseScreen waitForGivenTime
信息: ENTERING WAIT FOR GIVEN TIME
Executing testAddToCartForTV Scenario
九月 16, 2014 2:44:11 上午 ImplementationScreen addToCartForTV
信息: EXCEPTION IN addToCartForTV null
[Invoker 614877437] Invoking com.photon.phresco.testcases.iPhoneEshopTest.testcheckOutScenario
九月 16, 2014 2:44:11 上午 AbstractBaseScreen waitForGivenTime
信息: ENTERING WAIT FOR GIVEN TIME
Executing checkOutScenario Scenario
九月 16, 2014 2:44:14 上午 ImplementationScreen checkOutScenario
信息: EXCEPTION IN checkOutScenario null
[Invoker 614877437] Invoking @AfterClass iPhoneEshopTest.tearDown()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]
九月 16, 2014 2:44:14 上午 AbstractBaseScreen quitDriver
信息: ENTERING QUITDRIVER OPERATION
===== Invoked methods
  iPhoneEshopTest.setup(java.lang.String, java.lang.String, java.lang.String)[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524]iPhone simulator iOS 7.1  2109957412
    iPhoneEshopTest.testLogin()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524] 2109957412
    iPhoneEshopTest.testAddToCartForTV()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524] 2109957412
    iPhoneEshopTest.testcheckOutScenario()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524] 2109957412
  iPhoneEshopTest.tearDown()[pri:0, instance:com.photon.phresco.testcases.iPhoneEshopTest@7dc36524] 2109957412
=====
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/Mydevice/iPhoneHybEshopTest.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/Mydevice/iPhoneHybEshopTest.xml
PASSED: testLogin
PASSED: testAddToCartForTV
PASSED: testcheckOutScenario

===============================================
    iPhoneHybEshopTest
    Tests run: 3, Failures: 0, Skips: 0
===============================================


===============================================
Mydevice
Total tests run: 3, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4f47d241: 49 ms
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/toc.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/iPhoneHybEshopTest.properties
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/index.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/main.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/groups.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-alphabetical.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/classes.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/reporter-output.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/methods-not-run.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/Mydevice/testng.xml.html
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/old/index.html
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@e6ea0c6: 80 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@67f89fa3: 51 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@532760d8: 15 ms
Creating /Users/yunfeiyang/快盘/Example/JavaCode/functional/test-output/junitreports/TEST-com.photon.phresco.testcases.iPhoneEshopTest.xml
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@27ddd392: 7 ms

#12 楼 @wangcityboy 我一般都是真机,而且是 android,没启动模拟器就成功了。。真新鲜

#13 楼 @cy_suncheng
运行 xml 文件中方法是这个类,而这个类中不具有启动模拟器的功能

具有启动模拟器的功能,应该是启动这个类,而这个类不具有运行功能,该如何处理。

#14 楼 @wangcityboy 手动启动模拟器啊

#15 楼 @lihuazhang 再请教一下,这个类是用来干嘛的呢?这个可以用来自动启动模拟器么。

#16 楼 @wangcityboy 能否贴代码,不贴图?初看是启动 iOS 设备的。

#17 楼 @lihuazhang 好的,明白。。

#17 楼 @lihuazhang 那如何利用这个类进行自动启用模拟器呢?

#19 楼 @wangcityboy 。。。我怎么知道,这个代码是你们公司自己写的。

#20 楼 @lihuazhang 这个是网上的例子,我是用来学习的。

#21 楼 @wangcityboy 哦 那你学习,得研究呀,别一直让别人研究。。

#21 楼 @wangcityboy 另外你如果要大家帮忙一起 至少把源码分享出来。

#23 楼 @lihuazhang ios 版的找不到下载地址

#14 楼 @wangcityboy 你把启动模拟器的那段代码放到 setup 里面试试,然后我觉得你如果是刚开始学,你不用这样,还是应该用你们自己的 app,从最开始的 launch 开始自己写,你这样直接看别人的,都是别人的思路

#25 楼 @cy_suncheng 谢谢,这个我明白。。那个问题我已经解决了。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册