北京 线下三期 selenium 进阶课 0722

POM添加TestNG

 <dependency>            
<groupId>org.testng</groupId>            
<artifactId>testng</artifactId>            
<version>6.14.0</version>        
</dependency>

创建XML-TEST PLAN

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="myPlan" >
    <test name="Test">
        <classes>
            <class name="test.BeforeClass1"/>
            <class name="test.BeforeClass2"/>
        </classes>
    </test> <!-- Test -->
</suite> 

脚本添加读取csv代码

public Iterator<Object[]> readDataFromCSV(String path){
        List<Object[]> list = new ArrayList<Object[]>();
        try {
            FileReader is = new FileReader(new File(path));
            BufferedReader br = new BufferedReader(is);
            while(br.ready()){
                list.add(br.readLine().split(","));
            }
            return list.iterator();
        }catch(Exception ex){
            throw new SkipException(ex.getMessage());
        }
    }

POM添加读取Excel依赖

 <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
</dependency>

脚本添加读取excel代码

public Object[][] getDataFromExcel(String excelPath) {
        Workbook workbook;
        try {
            FileInputStream excelInputStream = new FileInputStream(excelPath);
            workbook = new XSSFWorkbook(excelInputStream);
            Sheet sheet = workbook.getSheetAt(0);
            int rowInExcel = sheet.getPhysicalNumberOfRows();
            int columnInExcel = sheet.getRow(0).getPhysicalNumberOfCells();
            String[][] obj = new String[rowInExcel-1][columnInExcel];
            for(int row = 1; row < rowInExcel; row++){
                for(int col = 0; col < columnInExcel; col++){
                    sheet.getRow(row).getCell(col).setCellType(Cell.CELL_TYPE_STRING);
                    obj[row - 1][col] = sheet.getRow(row).getCell(col).getStringCellValue();
                    System.out.println(obj[row - 1][col]);
                }
            }
            return obj;
        }catch(Exception e){
            throw new SkipException(e.getMessage());
        }

    }

POM添加AUTOIT依赖

<dependency>
            <groupId>AutoIt</groupId>
            <artifactId>AutoItX4Java</artifactId>
            <version>1.0</version>
</dependency>

POM添加apache依赖

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

AutoIT下载

作业
登录失败流程,要求
1、使用PO模式
2、使用TESTNG框架
3、加入验证点
4、尽量使用数据驱动的方式,讲几种登录失败的情况都覆盖到。数据放在CSV文件中。
5、尽量使用CSS/XPATH的定位方式来定位

关闭