0

我想在两台不同的机器上运行我的代码(到目前为止,我已经将我的本地机器注册为集线器和 2 个节点),所以在运行 testng.xml 文件时我遇到了错误。

运行 testng.xml 文件时出现错误,应用程序出现错误:- 请查看我的 testng.xml 文件和下面给出的代码:-

My testng.xml file is:- 

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" thread-count="4" parallel="tests">

    <test name="PVR Test">
    <parameter name="remoteurl" value="http://localhost:5555/wd/hub" />
        <classes>
            <class name="dd_testcases.login">
                <methods>
                    <include name="banner_check" />
                </methods>
            </class>
        </classes>
    </test> <!-- Test -->

    <test name="footersection">
    <parameter name="remoteurl" value="http://localhost:5556/wd/hub" />

        <classes>
            <class name="dd_testcases.News_General_Footer">
                <methods>
                    <include name="News_General_Footer" />
                </methods>
            </class>
        </classes>
    </test>
    Test
</suite> <!-- Suite -->

and my code is :-

    @BeforeSuite

    @Parameters("remoteurl")

    public void init(String remoteurl) throws IOException, InterruptedException{
        //BasicConfigurator.configure();
        dbcon=new sqldbconfig();
        logs=Logger.getLogger("PVR");
        config=new Properties();
        OR=new Properties();

        if (driver==null){

            InputStream is = getClass().getResourceAsStream("/config.properties");
            config.load(is);
            //fis=new FileInputStream(config.getProperty("confpath"));

            fis=new FileInputStream(System.getProperty("user.dir")+config.getProperty("ORpath"));
            //fis=new FileInputStream(System.getProperty("user.dir")+"\\src\\dd_properties\\OR.properties");
            OR.load(fis);

            //fis=new FileInputStream(config.getProperty("xlspath"));   
            excel=new Xls_Reader(System.getProperty("user.dir")+config.getProperty("xlspath"));
            System.out.println("Browser:: "+config.getProperty("Browser"));
            if (config.getProperty("Browser").equalsIgnoreCase("Mozilla")){
                cap=DesiredCapabilities.firefox();
                cap.setBrowserName("firefox");
                cap.setPlatform(Platform.ANY);
            }
            else if(config.getProperty("Browser").equalsIgnoreCase("chrome")){
                cap=DesiredCapabilities.chrome();
                cap.setBrowserName("chrome");
                cap.setPlatform(Platform.ANY);  
            }
        driver=new RemoteWebDriver(new URL(remoteurl),cap);
            driver.get(config.getProperty("testurl"));

and when i run via testng.xml file code throws error:-

org.testng.TestNGException: 
Parameter 'remoteurl' is required by @Configuration on method init but has not been marked @Optional or defined
in C:\Users\HT1\workspace\PVRGrid-A\testng.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:148)
    at org.testng.internal.Parameters.createParameters(Parameters.java:361)
    at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:84)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:197)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:296)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
    at org.testng.TestNG.run(TestNG.java:1018)
    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)

Please help me.....what i am doing wrong....
4

2 回答 2

0

为什么要在 @beforesuite 中创建驱动程序?它应该在@beforeclass 中创建。它只有一个驱动程序对象。我也不确定你的方法是如何访问这个驱动程序对象的,因为你还没有发布实际的方法。但我认为问题在于您的方法使用与之前套件相同的驱动程序对象仅运行一次。

于 2016-04-14T13:09:08.943 回答
0

您已在 TestNG xml 的测试级别将“remoteurl”定义为参数,而在代码中您在 init() 中的套件级别引用。通过在套件标记后声明将参数更改为 TestNG xml 中的套件级别,它应该可以工作。在套件级别声明 url 是有意义的,因为所有测试都将使用相同的服务器会话运行。

于 2016-04-14T06:51:04.120 回答