package com.xchanging.selenium.testcases.testng;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.xchanging.selenium.utility.CaptureScreenShot;
import com.xchanging.selenium.utility.ClearText;
import com.xchanging.selenium.utility.ClickEvent;
import com.xchanging.selenium.utility.GlobalVariables;
import com.xchanging.selenium.utility.ReadRows;
import com.xchanging.selenium.utility.SelectCheckBox;
import com.xchanging.selenium.utility.SelectDropDown;
import com.xchanging.selenium.utility.Text;
import com.xchanging.selenium.utility.VerifyText;
public class RegisterAccount extends GlobalVariables {
@Test(dataProvider = "getData")
public static void register() throws IOException {
ClickEvent.clickAt("createAccount_xpath");
Text.enterText("username_name", "username");
Text.enterText("password_name", "machans");
Text.enterText("confirmPassword_name", "machans");
ClickEvent.clickAt("securityquestion_name");
SelectDropDown.select("securityquestion_name", "petname");
Text.enterText("securityanswer_xpath", "vsbhss");
Text.enterText("fullName_name", "Chandrasekaran");
Text.enterText("email_name", "[email protected]");
ClearText.clear("dob_name");
Text.enterText("dob_name", "11/11/1982");
SelectDropDown.select("gender_name", 1);
SelectDropDown.select("marital_name", 1);
SelectDropDown.select("country_name", "India");
SelectCheckBox.selectchkbox("checkbox_xpath");
ClickEvent.clickAt("register_xpath");
VerifyText.verify("Congratulations.. You have registered successfully");
VerifyText.verify("Login now");
CaptureScreenShot.screenshot("Registration_Successful");
ClickEvent.clickAt("closebutton_xpath");
}
@DataProvider
public ArrayList<HashMap> getData() throws IOException {
ArrayList<HashMap> table = ReadRows.readExcel("Sheet1");
return table;
}
}
現在我想使用此DataProvider並從xls獲取值,並且必須在我的@Test部分中使用它。如何在TestNG中使用@DataProvider
任何人都可以幫忙嗎???
如果我使用,這樣一來它工作正常..
ArrayList<HashMap> table = ReadRows.readExcel("Sheet1");
table.get(0).get("email")
但我想用@dataProvider ..
我有這個方法ReadRows.readExcel(「Sheet1」);以檢索Excel表格..我可以採取一些邏輯從這個值? – ChanGan
請參閱下面的URL。 http://poi.apache.org/spreadsheet/quick-guide.html – Paras
我已經使用這個邏輯,我能夠使用ReadRows.readExcel(「Sheet1」)檢索數據。唯一的事情是如何定製在DataProvider中使用它 – ChanGan