2017年11月17日 星期五

Integration test (2) - Selenium

Selenium
 - Selenium webdriver是open source,可以針對編寫操作web的code
 - 為了Browser automation所設計的工具集合,讓程式可以直接驅使web做網站操作
  - 能夠直接獲取內容,可以和網頁互動,執行JavaScript,訪問Dom,模擬鍵盤輸入
 - 實現UI測試全自動化及做回歸測試
 - 由於瀏覽器有不同行為,所以需要進行維護

以下為編寫注意事項
  1. 使用DOM的ID進行定位-> 不受element位置更動而變動例如UI改版
  2. 特定項目操作繼承來設計class
  3. 使用Page Object Pattern,將所有頁面應該要使用到的操作放在一起,並由class使用
  4. 替測試做重試功能,直到成功或timeout
下載流程:
  1. 至http://www.seleniumhq.org/download/maven.jsp
  2. 可以看到對maven的dependency,並加入在pom.xml內,另可把版號放入properties裡
  3.   <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <selenium.version>3.7.1</selenium.version>
      </properties>
    
      <dependencies>
       <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>  
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>
    
  4. 可以至路徑 ~/.m2/repository 底下看到org的packages




沒有留言:

張貼留言