0

I want to run my code on two different machines (as of now i have registered my local machine as hub and 2 nodes), so while running testng.xml file i am getting below error.

I am getting error while running testng.xml file, application thorws error:- please see my testng.xml file and my code given below:-

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....
Curious
  • 282
  • 4
  • 21
Suresh Sharma
  • 186
  • 1
  • 5
  • 23
  • actually i made a framework and rest of the code is in other class files (that i have not mentioned here) because i am getting error in @BeforeSuite annotation – Suresh Sharma Apr 14 '16 at 05:46

2 Answers2

0

You have defined "remoteurl" as a parameter at test level in TestNG xml, whereas in the code you are referring at suite level in init(). Change the parameter to suite level in TestNG xml by declaring after the suite tag and it should work. Declaring the url at suite level makes sense as all the tests will be running using the same server session.

Akbar
  • 1,513
  • 4
  • 20
  • 34
  • Thanks!! As per your comment i made changes and pass parameters in suite lvl but this doesn't help me out. Now it opens the two browsers in two different machines but runs application only in one machine and not in the second machine. – Suresh Sharma Apr 14 '16 at 09:53
  • Perhaps something to do with local being registered as Hub and Nodes. I suggest you close this issue and open another for Selenium grid related. I have not worked extensively on Grid to suggest any solution. – Akbar Apr 15 '16 at 05:18
0

Why are you creating the driver in @beforesuite ? It should be create in @beforeclass. It has only one driver object .. Also I am not sure how your method accesses this driver object since you have not posted the actual method. But i think the problem is your methods are using the same driver object as the before suite is only run once.

Shamik
  • 1,591
  • 2
  • 16
  • 36
  • Exactly you got my problem...that's the problem, i created same object of "RemoteWebDriver"class. That's why my @BeforeSuite runs with one remote url. So please let me know if i want to run the same script on two different remote urls (two different machine/nodes) then i need to create two different object of "RemoteWebDriver" class or is there any way to run the whole code on two different machines with same RemoteWebDriver object? Pls help!!! – Suresh Sharma Apr 15 '16 at 05:20
  • Try creating the driver object inside your test class. Since you haven't posted that i code i cant help you on that. – Shamik Apr 16 '16 at 06:35
  • Try creating the driver object inside your test class. Since you haven't posted that i code i cant help you on that. Your driver object should be an instance variable of your test class and should not be shared. You should get tje the driver ojject by hitting your grid. The rest grid will take care. – Shamik Apr 16 '16 at 06:41