jenkins maven testng selenium自动化持续集成
生活随笔
收集整理的這篇文章主要介紹了
jenkins maven testng selenium自动化持续集成
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
準備環境
首先我們新建一個maven的工程,并且在pom.xml中配置好我們依賴的一些jar包
<dependencies><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>2.46.0</version></dependency><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>6.9.6</version></dependency><dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-api</artifactId><version>2.46.0</version></dependency></dependencies>編寫我們selenium腳本
public class NewTest {private WebDriver driver;@BeforeTestpublic void beforeTest(){driver = new FirefoxDriver();driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);driver.manage().window().maximize();driver.get("http://www.baidu.com");}@AfterTestpublic void afterTest(){driver.quit();}@Testpublic void f(){System.out.println("heloo");By inputBox = By.id("kw");By searchButton = By.id("su");//智能等待元素加載出來intelligentWait(driver, 10, inputBox);//智能等待元素加載出來intelligentWait(driver, 10, searchButton);driver.findElement(inputBox).sendKeys("中國");driver.findElement(searchButton).click();}/**這是智能等待元素加載的方法*/public void intelligentWait(WebDriver driver,int timeOut, final By by) {try {(new WebDriverWait(driver, timeOut)).until(new ExpectedCondition<Boolean>() {public Boolean apply(WebDriver driver) {WebElement element = driver.findElement(by);return element.isDisplayed();}});} catch (TimeoutException e) {Assert.fail("超時L !! " + timeOut + " 秒之后還沒找到元素 [" + by + "]", e);}} }再來還要配置下我們的testng.xml文件
<?xml version="1.0" encoding="UTF-8"?> <suite name="Suite" parallel="false"><test name="Test"><classes><class name="com.saii.NewTest"><methods><include name="f" /></methods></class></classes></test> </suite>工程配置已經結束了,我們來進行jenkins的一些配置吧。進入jenkins的系統配置?
配置全局屬性的鍵值對?
這個地方一定要配置,因為如果不配置成utf-8的話,jenkins從git上拉下來的文件編碼格式不是utf-8的格式,這樣子就會導致文件中的一些中文直接變成了亂碼,到時候直接影響到腳本的運行?
進行maven的項目配置?
這里是配置maven的編碼以及防止oom還有是maven的本地倉庫以及maven的安裝地址
新建一個projce后,在構建中新建一個構建步驟 invoke-top-level Maven targets?
這里只需要配置正確pom就可以了。
運行結果?
OK 運行成功!
總結
以上是生活随笔為你收集整理的jenkins maven testng selenium自动化持续集成的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何为APK签名?
- 下一篇: 你一写长文章就焦虑拖延?