(1)什麼是框架?java
(2)爲何要寫框架?git
(3)框架的幾個要素?github
package com.lixx.drivers; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class SeleniumDriver1 { public static WebDriver driver; public static WebDriver initialDriver(String browser){ //獲取當前工程根目錄 String path = System.getProperty("user.dir"); if (browser.equals("chrome")){ System.setProperty("webdriver.chrome.driver", path + "/driver/chromedriver.exe"); driver = new ChromeDriver(); }else if (browser.equals("ie")){ System.setProperty("webdriver.ie.driver", path + "/driver/IEDriverServer.exe"); driver = new InternetExplorerDriver(); }else if (browser.equals("firefox")){ driver = new FirefoxDriver(); }else if (browser.equals("edge")){ System.setProperty("webdriver.edge.driver", path + "/driver/MicrosoftWebDriver.exe"); driver = new EdgeDriver(); }else { System.out.println("您輸入的瀏覽器名稱有誤,請確認!"); } return driver; } }
經常使用類封裝-隨機數封裝web
截圖方法封裝chrome
Assert類封裝瀏覽器
經過TestNg作數據驅動框架
PO理念的引入dom
監聽錯誤自動重跑和截圖測試