简体   繁体   中英

How can i send multiple test data using testng in to following

Please suggest me how to sent 3 users in 3 browsers for this field

driver.findElement(By.id(PropertiesConfiguration.getMyProperty("PinTextfield"))).sendKeys(PropertiesConfiguration.getMyProperty("user")); 

// main class

public  class TestHRWW {`main class`

protected WebDriver driver;
@Parameters("browser")`parameter for browser initialization`
@BeforeClass
public  void setup(String browser) {
    if (browser.equalsIgnoreCase("firefox")) {
        driver = new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("iexplorer")) {
        System.setProperty("webdriver.ie.driver","Drivers\\IEDriverServer.exe");
        driver = new InternetExplorerDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {
        System.setProperty("webdriver.chrome.driver","Drivers\\chromedriver.exe");
        driver = new ChromeDriver();
    }
    else {
        throw new IllegalArgumentException("The Browser Type is Undefined");
    }
    driver.manage().window().maximize();
}

@BeforeMethod
public void open() {
    driver.get("http://www.myhrasiapacific.com/");
}
@AfterClass
public void teardown() {
    try {
        driver.quit();
    } catch (Exception e) {
        driver = null;
    }

}

// sub class
public class Login extends TestHRWW {`sub class`
    String x;
    static Logger logger = Logger.getLogger(Login.class.getName());
@Test   
    public void ClickLogon(WebDriver driver) throws InterruptedException, IOException {
        driver.findElement(`enter code here`
                By.id(PropertiesConfiguration.getMyProperty("logonbutton")))
                .click();
        Thread.sleep(2000);
       // here i need to sent 3 differt users credentials
        driver.findElement(
                By.id(PropertiesConfiguration.getMyProperty("PinTextfield")))
                .sendKeys(PropertiesConfiguration.getMyProperty("user"));
        Thread.sleep(2000);
        driver.findElement(
                By.id(PropertiesConfiguration
                        .getMyProperty("passwordTextfield"))).sendKeys(
                                PropertiesConfiguration.getMyProperty("password"));
        Thread.sleep(2000);
        driver.findElement(
                By.id(PropertiesConfiguration.getMyProperty("loginbutton")))
                .click();
        driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    }

}

You shall use TestNG @DataProvider to pass username & passwords

your login method will be like

@Test(dataProvider="dataForLogin")
public void ClickLogon(String userName,String password) {
}

@DataProvider(name="dataForLogin")
public static Object[][] prepareDataForLogin(){
        // preparation of login data
}

If you are using QAF then you don't need to manually parse your json data and get rid from data provider class.

public class tDataHelper {
    private static List<String> studentsToCreate = new ArrayList<String>();

    static void parseData() throws Exception {
        studentsToCreate.add("user1");
        studentsToCreate.add("user2");
        studentsToCreate.add("user3");
    }

    @DataProvider
    public static Object[][] createStudents() {
        Object[][] objArray = new Object[studentsToCreate.size()][];
        for (int i = 0; i < studentsToCreate.size(); i++) {
            objArray[i] = new Object[1];
            objArray[i][0] = studentsToCreate.get(i);
        }
        return objArray;
    }
}

public class testStudents {
    private static tDataHelper helper = new tDataHelper();

    @BeforeClass
    public void setup() throws Exception {
        tDataHelper.parseData();
    }
    @Test(dataProvider = "createStudents", dataProviderClass = tDataHelper.class)
    public void testCreateStudents(String studentsToCreate) {
        System.out.println(studentsToCreate);
    }
}

QAF Test Data Driven

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM