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部分中使用它。
[任何人都可以帮忙吗???
如果使用,则可以正常工作。。
ArrayList<HashMap> table = ReadRows.readExcel("Sheet1");
table.get(0).get("email")
但是我想使用@DataProvider ..
如何管理。.>
@Test(dataProvider="getData") public static void register(ArrayList<HashMap> table) throws IOException { }
这解决了我的问题。
在测试类中,声明以下方法,以提供要插入测试的数据。确保它返回一个新的Object数组,甚至返回一个二维数组,例如您需要的Object [] []。
如果要使用dataProvider
批注。带注释的方法必须返回Object[][]
,可以为每个Object []分配测试方法的参数列表。