Tag: testng

根据一列读取excel数据并提交给java类

我目前从Excel工作表中抽取我的数据,并使用testNG的dataProvider注释传递给我的testing。 我从Excel中返回数据的代码如下。 public static Object [][] excelData(String filepath) throws Exception { File excelFilePath = new File (filepath); FileInputStream fis = new FileInputStream(excelFilePath); HSSFWorkbook wb = new HSSFWorkbook(fis); HSSFSheet ws = wb.getSheet("Data"); int rowNum = ws.getLastRowNum()+1; int colNum = ws.getRow(0).getLastCellNum(); Object[][] data = new Object[rowNum][colNum]; for (int i=0; i<rowNum; i++){ HSSFRow row = ws.getRow(i); for (int […]

我需要在使用POI的指定列上写excel的pass失败

好的 – 所以我意识到在编写一些代码并弄清楚之后,jxl不支持xlsx,只支持POI(XSSF)。 好的。 我想要做的是在指定的列中search一个string值为“Result”的单元格。 一旦我发现,那么当testing通过或失败时,它会在空白的单元格中写入“通过”或“失败”。 它将继续这样做,直到testing集完成。 这是我用jxl编写的代码。 WritableWorkbook wb = Workbook.createWorkbook(new File(testData), workbook); WritableSheet ws = wb.getSheet("OrderCreateQA3"); int colCount = ws.getColumns(); for(int j=0; j<colCount; j++){ Cell cell = ws.getCell(j,0); if(cell.getContents().contains("Result")){ Cell[] cells = ws.getColumn(j); int len = cells.length; Label label = new Label(j,len, "Fail", getCellFormat(Colour.RED)); ws.addCell(label); break; } } wb.write(); wb.close(); 上面是相当简单的,我findstring,然后获得该列名称,并写入通过或失败的长度。 任何想法如何使用兴趣点做到这一点?

代码执行成功,但数据只在最后一次迭代时才添加到Excel中

我需要帮助的人,我卡在一个点。 这是我的代码之后的方法 @AfterMethod public void writeResult(ITestResult result) throws IOException, Exception { Workbook workbk = Workbook.getWorkbook(new File("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls")); WritableWorkbook bookk = Workbook.createWorkbook(new File("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest_Written.xls"),workbk); int methodCellColumn =findCellLocationColumn("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls", methodName); int methodCellRow =findCellLocationRow("D:\\Selenium Automation\\Selenium\\Framework\\Prototype\\Output\\eLogistics_Result_Latest.xls", methodName); if(result.getStatus() == ITestResult.SUCCESS) { System.out.println("Method-"+methodName+"- has Passed"); writeDataInCell(methodCellColumn+3, methodCellRow,"Pass",bookk); System.out.println("Method Column number is-> "+(methodCellColumn+3)); System.out.println("Method row number is-> "+methodCellRow); } else if(result.getStatus() […]

当selenium自动化testing用例场景失败时,如何报告我的Excel表格失败?

情景是: 1)打开浏览器。 2)导航到应用程序URL。 3)这里来了棘手的部分: 驱动程序几乎大部分时间都可以使用sendkeys()方法input用户名和密码。 但在极less数情况下,驱动程序无法执行操作,login页面只能冻结。 这是我的脚本: driver.findElement(XPATH).sendKeys(userName); driver.findElement(XPATH).sendKeys(password); driver.findElement(XPATH).click(); // waiting for landing page to load Thread.sleep(70000); elib.setExcelData("DATA", 1, 4, "PASS"); 当一切正常,它inputPASS在我的Excel表单。 现在,在login页面挂起的情况下,如何在excel表格中inputFAIL? 注意:我是使用Java语言的selenium webriver。

如何迭代excel表使用testNG dataprovider多组数据?

我一直在使用TestNg一段时间,但我有一个新的需求,我似乎无法弄清楚。 我有一个Excel文件(sample.xls),工作表名称=数据集具有以下内容: testdata1 ex1 ex2 ex3 ex4 1 2 3 4 testdata1 testdata2 ex1 ex2 ex3 ex4 5 6 7 8 testdata2 我的脚本与此类似: import com.thoughtworks.selenium.*; import org.junit.AfterClass; import org.openqa.selenium.server.SeleniumServer; import org.testng.annotations.*; import java.io.File; import jxl.*; public class DataProviderExample extends SeleneseTestCase{ @DataProvider(name = "DP1") public Object[][] createData1() throws Exception{ Object[][] retObjArr=getTableArray("test\\Resources\\Data\\sample.xls", "DataPool", "testdata1"); return(retObjArr); } @Test […]

每次我写入excel时,都会用空白文件覆盖整个文件–PUZZLED

我正在尝试做的是onTestFailure(TestNG)我想写一个通过/失败到指定的列。 在下面的代码中,我只是想做一些testing,将Fail写入指定的单元格。 但是现在发生的事情是,它不是写入指定单元格的合格/不合格,而是覆盖整个文件并擦除所有的数据,我为此感到困惑。 我在这里看了一下,但是找不到答案。 以下是以下代码: @Override public synchronized void onTestFailure(ITestResult tr){ try { Workbook workbook = Workbook.getWorkbook(new File(testData), workbookSettings); WritableWorkbook wb = Workbook.createWorkbook(new File(testData), workbook); WritableSheet ws = wb.getSheet("OrderEditQA3"); Label label = new Label(5,2, "Fail"); ws.addCell(label); wb.write(); } catch (IOException e) { e.printStackTrace(); } catch (BiffException b){ System.out.print("Error!"); } catch (WriteException we){ System.out.print(""); } } […]

TestNG使用DataProviders错误的参数数目

<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" parallel="tests" configfailurepolicy="continue" thread-count = "10" verbose="1"> <parameter name="dev" value="true"></parameter> <test name ="Chrome" parallel="methods"> <parameter name="myBrowser" value="chrome" /> <classes> <class name="package.TestClass"></class> </classes> </test> <test name ="Firefox" parallel="methods"> <parameter name="myBrowser" value="firefox" /> <classes> <class name="package.TestClass"></class> </classes> </test> </suite> 在这个.xml文件中,我有一个名为“dev”的参数设置为true。 我试图让我的数据提供者读取这个variables,并使用不同的Excel表,如果是的话。 @Parameters("dev") @DataProvider(parallel = true) public Object[][] testData(String dev) { String path; if(dev.equals(true)){ […]