@Configuration方法setUp上需要参数'google',但尚未将其标记为@Optional或已定义 [英] Parameter 'google' is required by @Configuration on method setUp but has not been marked @Optional or defined

查看:197
本文介绍了@Configuration方法setUp上需要参数'google',但尚未将其标记为@Optional或已定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于同一错误,有几个线程,但是它们不处于活动状态,我认为最后一次处于活动状态的时间大约是1年,所以我要打开新线程.

There are couple of thread regarding same error but they are not active ,I think last they were active was around 1 yr back so I am opening the new thread .

Testng.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="1">
    <parameter name="google" value="http://www.ezeego1.co.in/" />
    <test name="Test">
        <classes>
            <class name="selenium.karma.bu.DriverApp" />
            <class name="selenium.karma.bu.ReadSuite" />
        </classes>
    </test> <!-- Test -->
</suite> <!-- Suite -->

DriverApp.java :-

公共类DriverApp {

public class DriverApp {

public static WebDriver driver;

@Parameters("google")
@BeforeSuite
public void setUp(String appUrl) throws Exception{

    ProfilesIni prof = new ProfilesIni();
    FirefoxProfile p = prof.getProfile("default");
    p.setPreference("extensions.headertool.preferencies.editor", "sm_universalid: swkv8851\nftusergivenname: vidushi \nftusersn: shukla\nftapplicationroles: Admin\nftusercredentials: ES,PL\n\n");;
    p.setPreference("extensions.headertool.preferencies.onoff", true);

     driver = new FirefoxDriver(p);
     driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

    driver.get("http://10.171.23.218:3080/karmaGui/karmaGui/KarmaGui.html?locale=en#Main") ;
    Thread.sleep(5000);
    driver.manage().window().maximize();
}

并且我们已经将其扩展到另一个Java类readsuite.java.

And we have extended it to another java class readsuite.java.

当我用testng执行ReadSuite.java时,出现以下错误:-

When I execute my ReadSuite.java with testng I get following error:-

Total Rows Accross the sheets : 0
FAILED CONFIGURATION: @BeforeSuite setUp
org.testng.TestNGException: 
Parameter 'google' is required by @Configuration on method setUp but has not been marked @Optional or defined
in C:\Users\swkv8851\AppData\Local\Temp\testng-eclipse--1721497351\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.SuiteRunner.privateRun(SuiteRunner.java:277)
    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)

此处

C:\ Users \ swkv8851 \ AppData \ Local \ Temp \ testng-eclipse--172149735 enter code here 1 \ testng-customsuite.xml在运行时创建并且其内容是

C:\Users\swkv8851\AppData\Local\Temp\testng-eclipse--172149735enter code here1\testng-customsuite.xml get created at run time and it contents are

<suite name="Default suite">
    <test verbose="2" name="Default test">
        <classes>
            <class name="selenium.karma.bu.ReadSuite" />
        </classes>
    </test>
    <!-- Default test -->
</suite>
<!-- Default suite -->

请帮助我确定错误.

当我在driverapp.java中评论@parameter和@Beforesuite时,没有出现此错误,但随后未调用我的浏览器.

When I comment @parameter and @Beforesuite in driverapp.java I do not get this error but then my browser is not invoked.

推荐答案

尽管这是一篇很老的文章,但我正在分享对我有用的解决方案.

Though it seems to be a very old post, I am sharing the solution which worked for me.

基本上,它需要对TestNG Run'Class'和'Suite'进行两项设置

Basically it requires two settings for TestNG Run 'Class' and 'Suite'

设置TestNG运行'Class'
步骤1:转到项目=>运行方式=>运行配置=>'测试'选项卡
第2步:选中选项类".它应该是具有所需".java"文件的集合.
例如'functionalTestCases.java'位于软件包'testCases'上,然后将'Class'设置为'testCases.functionalTestCases.java'
步骤3:验证名称"字段. 例如可以是'functionalTC'
步骤4:使用应用"按钮保存更改

To set the TestNG Run 'Class'
Step1: Goto Project => Run As => Run Configurations => 'Test' tab
Step2: Check option 'Class'. It should be the set with desired '.java' file.
e.g. 'functionalTestCases.java' is on package 'testCases' then 'Class' will be set as 'testCases.functionalTestCases.java'
Step3: Verify the 'Name' field. e.g It can be 'functionalTC'
Step4: Save the changes using 'Apply' button

设置TestNG运行'Suite' 步骤1:转到项目=>运行方式=>运行配置=>'测试'选项卡
第2步:选中选项套房".它应该是具有所需"testng.xml"文件路径的集合.
步骤3:验证名称"字段.
例如可以是'projectname_testng.xml'
步骤4:使用应用"按钮保存更改

To set the TestNG Run 'Suite' Step1: Goto Project => Run As => Run Configurations => 'Test' tab
Step2: Check option 'Suite'. It should be the set with desired 'testng.xml' file path.
Step3: Verify the 'Name' field.
e.g It can be 'projectname_testng.xml'
Step4: Save the changes using 'Apply' button

正确保存这些设置后,然后使用"projectname_testng.xml"运行项目

After these setting are saved properly, then Run the project with 'projectname_testng.xml'

此外,我在'testCases.functionalTestCases.java'中将该方法(引用并检查从'testng.xml'传递的'参数')用作'@BeforeClass'

Also, I am using TestNG annotation as '@BeforeClass' for the method (which refers and checks the 'parameter' passed from 'testng.xml') in 'testCases.functionalTestCases.java'

这篇关于@Configuration方法setUp上需要参数'google',但尚未将其标记为@Optional或已定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆