日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

第6章 Selenium2-Java 自动化测试模型

發(fā)布時間:2025/3/18 java 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第6章 Selenium2-Java 自动化测试模型 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

6.1 ?自動化測試模型介紹

??6.1.1 ?線性測試 :其實就是單純地來模擬用戶完整的操作場景。

? ? ? ? ? ? ? ?優(yōu)勢就是每一個腳本都是完整且獨立的;

     ? 缺陷測試用例的開發(fā)與維護成本很高。

??6.1.2 ?模塊化驅(qū)動測試 :編程語言中模塊化的思想,把重復的操作獨立成公共模塊,當用例執(zhí)行過程中需要用到這一模塊操作時則被調(diào)用,這樣就最大程度上消除了重復,從而提高測試用例的可維護性。

??6.1.3 ?數(shù)據(jù)驅(qū)動測試 :數(shù)據(jù)的改變從而驅(qū)動自動化測試的執(zhí)行,最終引起測試結(jié)果的改變.(我們讀取的是定義的數(shù)組、字典,或者是外部文件(excel、csv、txt、xml等)都可以看作是數(shù)據(jù)驅(qū)動。)

??6.1.4 ?關(guān)鍵字驅(qū)動測試:

6.2 ?模塊化實例

? ??線性測試實例:

package com.cy;import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;public class TestModel {public static void main(String[] args) throws InterruptedException {System.out.println("博客園登錄 操作 退出");WebDriver driver =new FirefoxDriver();driver.get("https://passport.cnblogs.com/user/signin?AspxAutoDetectCookieSupport=1");// 清除input 輸入用戶名driver.findElement(By.id("input1")).clear();driver.findElement(By.id("input1")).sendKeys("Smile燕");// 清除input 輸入密碼driver.findElement(By.id("input2")).clear();driver.findElement(By.id("input2")).sendKeys("acy123");// 點擊登錄driver.findElement(By.id("signin")).click();Thread.sleep(5000);/*** 操作*/// 退出driver.findElement(By.linkText("退出")).click();Thread.sleep(5000);// // 接受彈框 driver.switchTo().alert().accept();Thread.sleep(5000);// 關(guān)閉瀏覽器 driver.quit();}}

模塊化驅(qū)動測試實例: 把登錄和退出進行封裝。

?

package com.cy;import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;public class TestModel {public static void main(String[] args) throws InterruptedException {System.out.println("博客園登錄 操作 退出");WebDriver driver =new FirefoxDriver();/*** 操作*/login(driver);Thread.sleep(5000);logout(driver);Thread.sleep(5000);// 關(guān)閉瀏覽器 driver.quit();}public static void login(WebDriver driver) {driver.get("https://passport.cnblogs.com/user/signin?AspxAutoDetectCookieSupport=1");// 清除input 輸入用戶名driver.findElement(By.id("input1")).clear();driver.findElement(By.id("input1")).sendKeys("Smile燕");// 清除input 輸入密碼driver.findElement(By.id("input2")).clear();driver.findElement(By.id("input2")).sendKeys("acy123");// 點擊登錄driver.findElement(By.id("signin")).click();}public static void logout(WebDriver driver){// 退出driver.findElement(By.linkText("退出")).click();// // 接受彈框 driver.switchTo().alert().accept();}}

?我們可以把這兩個方法 封裝成單獨的文件中供其它用例調(diào)用。這樣對于每個用例來說就簡便了許多,也更易于維護。

數(shù)據(jù)驅(qū)動實例:前面提到關(guān)于數(shù)據(jù)驅(qū)動的形式有很多,我們既可以通過定義變量的方式進行參數(shù)化,也可以通過定義數(shù)組、字典的方式進行參數(shù)化,還可以通過讀取文件(txt\csv\xml)的方式進行參數(shù)化。

package com.cy;import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;public class TestModel {public static void main(String[] args) throws InterruptedException {System.out.println("博客園登錄 操作 退出");WebDriver driver =new FirefoxDriver();/*** 操作*/String username="Smile燕";String password="acy123@@";login(driver,username,password);Thread.sleep(5000);logout(driver);Thread.sleep(5000);// 關(guān)閉瀏覽器 driver.quit();}public static void login(WebDriver driver,String username,String password) {driver.get("https://passport.cnblogs.com/user/signin?AspxAutoDetectCookieSupport=1");// 清除input 輸入用戶名driver.findElement(By.id("input1")).clear();driver.findElement(By.id("input1")).sendKeys(username);// 清除input 輸入密碼driver.findElement(By.id("input2")).clear();driver.findElement(By.id("input2")).sendKeys(password);// 點擊登錄driver.findElement(By.id("signin")).click();}public static void logout(WebDriver driver){// 退出driver.findElement(By.linkText("退出")).click();// // 接受彈框 driver.switchTo().alert().accept();}}

關(guān)鍵字驅(qū)動測試實例:(未完待續(xù)哈。。。)

轉(zhuǎn)載于:https://www.cnblogs.com/hellokitty1/p/6382496.html

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的第6章 Selenium2-Java 自动化测试模型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。