杭州线下 20180610Selenium 课程帖

  • pom文件所需依赖
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.12.0</version>
        </dependency>
    </dependencies>
<dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.10</version>
</dependency>
<dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
</dependency>
public Object[][] getDataFromExcel(String excelPath) throws Exception{
            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++){
                    obj[row - 1][col] = sheet.getRow(row).getCell(col).getStringCellValue();
                    System.out.println(obj[row - 1][col]);
                }
            }
            return obj;
        }

作业1:需要把脚本转化成excel驱动的模式

作业2:将写的搜索功能转化成page object