0

コードを 2 つの異なるマシンで実行したいので (現在、ローカル マシンをハブと 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 で作成する必要があります。ドライバーオブジェクトは1つしかありません..また、実際のメソッドを投稿していないため、メソッドがこのドライバーオブジェクトにどのようにアクセスするかわかりません。しかし、問題は、スイートが一度しか実行されない前に、メソッドが同じドライバーオブジェクトを使用していることだと思います。

于 2016-04-14T13:09:08.943 に答える
0

TestNG xml のテスト レベルで「remoteurl」をパラメーターとして定義しましたが、コードでは init() のスイート レベルで参照しています。スイート タグの後に宣言することにより、TestNG xml でパラメーターをスイート レベルに変更すると、機能するはずです。すべてのテストが同じサーバー セッションを使用して実行されるため、スイート レベルで URL を宣言することは理にかなっています。

于 2016-04-14T06:51:04.120 に答える