Wednesday, January 19, 2011

How to parametrize the values in the Testng

package smoke;

import com.thoughtworks.selenium.*;

//import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.RemoteControlConfiguration; //import org.openqa.selenium.server.SeleniumServer;

import org.testng.annotations.*;

public class Popup extends SeleneseTestCase {
String trafficOutput;
public static Selenium selenium;
public static final String MAX_WAIT_TIME_IN_MS = "30000";

    boolean Condition = true;

    @BeforeSuite
    @Parameters( { "selenium.host", "selenium.port", "selenium.browser","selenium.url" })
    public void setUp(String host, String port, String browser, String url)
            throws Exception {

        RemoteControlConfiguration rc = new RemoteControlConfiguration();
        rc.setSingleWindow(true);
        rc.trustAllSSLCertificates();

        selenium = new DefaultSelenium(host, Integer.parseInt(port), browser,url);

        selenium.start();
   
        selenium.windowMaximize();
    }


This is how ur main program will look like and the XMl file where u can declare the parameters 


<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="test"  parallel="tests"  threadcount="5" >
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="4444"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="https:"></parameter>

<test name="test1" >
<classes>
<class name="smoke.Popup" />
</classes>
</test>

</suite>

No comments:

Post a Comment