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.Как использовать @DataProvider в TestNG
Может ли кто-нибудь помочь?
Если я использую, так он работает нормально ..
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