Java-将数组的第1列传递给driver.get()并断言到第2列
我正在编写一个脚本来验证URL重定向。我有一个有两列的电子表格。一列是我需要传递给driver.get()的URL,第二列是URL,它是预期的URL 我的问题是验证重定向URL。如何通过列[0]传递迭代,并将其传递给driver.get()。然后用列[1]断言Java-将数组的第1列传递给driver.get()并断言到第2列,java,selenium,testng,testng-dataprovider,Java,Selenium,Testng,Testng Dataprovider,我正在编写一个脚本来验证URL重定向。我有一个有两列的电子表格。一列是我需要传递给driver.get()的URL,第二列是URL,它是预期的URL 我的问题是验证重定向URL。如何通过列[0]传递迭代,并将其传递给driver.get()。然后用列[1]断言 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iter
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class UrlRedirectCheck {
public class ReadExcelDataProvider {
public WebDriver driver;
public WebDriverWait wait;
@BeforeClass
public void testSetup() {
driver=new FirefoxDriver ();
driver.manage().window().maximize();
wait = new WebDriverWait(driver, 5);
}
@Test(dataProvider="Urls")
public void VerifyRedirectURL(String RedirectedUrl, String ExpectedURL) {
// For loop for RedirectURL (column 1 from spreadsheet)
{
driver.get ();
driver.getCurrentUrl ();
// driver.getCurrentURL, column 2 from array
assert.assertEquals()
}
}
@DataProvider(name="Urls")
public Object[][] MilbURL() {
Object[][] arrayObject = getExcelData("<URL path>","Sheet1");
return arrayObject;
}
/**
* @param File Name
* @param Sheet Name
* @return
*/
@Test
public String[][] getExcelData(String fileName, String sheetName) {
String[][] arrayExcelData = null;
try {
FileInputStream fs = new FileInputStream (fileName);
Workbook wb = Workbook.getWorkbook(fs);
Sheet sh = wb.getSheet(sheetName);
int totalNoOfCols = sh.getColumns();
int totalNoOfRows = sh.getRows();
arrayExcelData = new String[totalNoOfRows-1][totalNoOfCols];
for (int i= 1 ; i < totalNoOfRows; i++) {
for (int j=0; j < totalNoOfCols; j++) {
arrayExcelData[i-1][j] = sh.getCell(j, i).getContents();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
return arrayExcelData;
}
@Test
public void tearDown() {
driver.quit();
}
}
import java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.IOException;
导入java.util.Iterator;
进口jxl.Sheet;
导入jxl.工作簿;
导入jxl.read.biff.BiffException;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.openqa.selenium.support.ui.ExpectedConditions;
导入org.openqa.selenium.support.ui.WebDriverWait;
导入org.testng.Assert;
导入org.testng.annotations.BeforeClass;
导入org.testng.annotations.DataProvider;
导入org.testng.annotations.Test;
公共类URL重定向检查{
公共类ReadExcelDataProvider{
公共网络驱动程序;
公共网络驱动器,它等待;
@课前
公共void testSetup(){
驱动程序=新的FirefoxDriver();
driver.manage().window().maximize();
等待=新的WebDriverWait(驱动程序,5);
}
@测试(dataProvider=“url”)
public void VerifyRedirectURL(字符串RedirectedUrl,字符串ExpectedURL){
//用于重定向URL的For循环(电子表格中的第1列)
{
driver.get();
driver.getCurrentUrl();
//driver.getCurrentURL,数组中的第2列
assert.assertEquals()
}
}
@数据提供者(name=“url”)
公共对象[][]MilbURL(){
对象[][]arrayObject=getExcelData(“,”Sheet1”);
返回arrayObject;
}
/**
*@param文件名
*@param表名
*@返回
*/
@试验
公共字符串[][]getExcelData(字符串文件名、字符串名称){
字符串[][]arrayExcelData=null;
试一试{
FileInputStream fs=新的FileInputStream(文件名);
工作簿wb=Workbook.getWorkbook(fs);
Sheet sh=wb.getSheet(sheetName);
int totalNoOfCols=sh.getColumns();
int totalNoOfRows=sh.getRows();
arrayExcelData=新字符串[totalNoOfRows-1][totalNoOfCols];
for(inti=1;i
}您面临的问题是什么?通过driver.get()传递字符串数组(第1列)。我想我需要一个驱动程序的for循环。get()。然后我可以断言URL和第2列中的URL相等。