文章目錄
- 項目背景
- 測試計劃
- UI測試
- 接口測試
- 手工測試
- 測試總結
項目背景
項目描述:“智力沖刺”是一款網頁小游戲,就像我們平時看到的網頁游戲一樣,前端頁面負責展示游戲效果,后端服務器來實現游戲的邏輯。在我們的“智力沖刺”游戲中,玩家從瀏覽器打開游戲登錄頁面(登錄或者注冊),登錄成功后進入游戲大廳,點擊開始匹配按鈕進入游戲房間進行對戰,分出勝負后給與玩家反饋。總共設計了三個模塊來進行功能的實現:
-
用戶模塊:用戶注冊(加鹽算法)、用戶登錄(攔截器+session持久化)、用戶天梯分數記錄、用戶比賽場次記錄
-
匹配模塊:根據用戶的天梯分數實現匹配機制
-
對戰模塊:實現兩個玩家在網頁端進行五子棋對戰的功能
測試計劃
UI測試
- 定位頁面
//定位頁面并截圖
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class IndexTest extends CommonDriver{/*** 獲取到這一個driver實例*/private static final FirefoxDriver driver= getDriver();@BeforeAllpublic static void getPage() throws InterruptedException, IOException {driver.get("http://localhost:8080/login.html");//需要對于首頁進行截圖//以文件的形式存儲File srcFile=driver.getScreenshotAs(OutputType.FILE);//把截圖的文件存放到指定的目錄下面File destFile=new File("D:/java_gobang/src/test/Files/index.png");Thread.sleep(1000);FileUtils.copyFile(srcFile,destFile);//設置隱式等待時間:最長3秒driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));}
}
- 測試“登錄”二字是否存在
/*** 測試:"登錄"是否存在*/@Test@Order(1)public void checkTittle(){WebElement webElement =driver.findElement(By.cssSelector("body > nav > a"));String text=webElement.getText();//斷言:二者是否一致Assertions.assertEquals("登錄",text);}
- 測試“用戶名”和“密碼”二字是否存在
/*** 測試:“用戶名”和“密碼”是否存在*/@Test@Order(2)public void checkProblemListTittles(){//測試:"用戶名"是否存在WebElement element1=driver.findElement(By.cssSelector("#tables > div > div > table > thead > tr > th:nth-child(1)"));String number=element1.getText();Assertions.assertEquals("用戶名",number);//測試:"密碼"是否存在WebElement element2=driver.findElement(By.cssSelector("#tables > div > div > table > thead > tr > th:nth-child(2)"));String tittle=element2.getText();Assertions.assertEquals("密碼",tittle);}
- 測試“注冊“鏈接是否跳轉
//獲取到注冊鏈接的css選擇器WebElement TittleLinkElement = driver.findElement(By.cssSelector("#"+tittleLinkedCss));//獲取注冊鏈接的實際內容String tittleReal = TittleLinkElement.getText();Assertions.assertEquals(tittleExcept, tittleReal);//點擊,看一下跳轉的結果:TittleLinkElement.click();try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}//截圖:看是否成功跳轉File srcFile=driver.getScreenshotAs(OutputType.FILE);//把截圖的文件存放到指定的目錄下面File destFile=new File("D:/java_gobang/src/test/Files/ProblemLinked"+numberExcept+".png");Thread.sleep(1000);FileUtils.copyFile(srcFile,destFile);
- 測試“提交“鏈接是否跳轉
//獲取到提交鏈接的css選擇器WebElement TittleLinkElement = driver.findElement(By.cssSelector("#"+tittleLinkedCss));//獲取提交鏈接的實際內容String tittleReal = TittleLinkElement.getText();Assertions.assertEquals(tittleExcept, tittleReal);//點擊,看一下跳轉的結果:TittleLinkElement.click();try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}//截圖:看是否成功跳轉File srcFile=driver.getScreenshotAs(OutputType.FILE);//把截圖的文件存放到指定的目錄下面File destFile=new File("D:/java_gobang/src/test/Files/ProblemLinked"+numberExcept+".png");Thread.sleep(1000);FileUtils.copyFile(srcFile,destFile);
接口測試
- 測試登錄接口是否正常
- 測試注冊接口是否正常
- 測試得到用戶信息接口是否正常
手工測試
測試總結
對登錄模塊、匹配模塊、對戰模塊分別進行測試。保證了頁面元素的完整性、正確性,信息的準確性,游戲邏輯的正確性。基本上排除了項目中的簡單問題,可以讓玩家獲得較好的游戲體驗。