經過本次實訓,認識到了軟體測試的多種技術,相比之前學過的,瞭解到了Charles這個抓包工具和app的測試方法。
第一天是寫了個登陸的測試用例,主要用到了黑盒測試的等價類劃分,邊界值分析,場景法,錯誤推斷等方法。
第二天是寫了個簡單的python程式,進行pytest測試。
第三天主要就是自動化的web測試,寫了selenium的測試指令碼,實現allure的測試報告生成。
下面是一段python的自動化測試程式碼:
import time import allure import pytest from selenium.webdriver.support import expected_conditions as EC from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait class TestAddAndDelete: def setup_class(self): self.driver = webdriver.Chrome() # 隱式等待,全域性等待時間 self.driver.implicitly_wait(10) # 開啟頁面 self.driver.get("https://litemall.hogwarts.ceshiren.com/#/login") self.driver.maximize_window() def teardown_class(self): # driver 退出 self.driver.quit() @allure.title("登入進入列表介面") def test_before(self): # 點選登入 with allure.step("登入按鈕點選"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/form/button").click() time.sleep(2) # 點選商品管理 with allure.step("點選商品管理"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[1]/div[1]/div/ul/div[3]/li/div").click() # 點選商品列表 with allure.step("點選商品列表"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[1]/div[1]/div/ul/div[3]/li/ul/div[1]/a/li").click() @allure.title("正確地新增三次") @pytest.mark.parametrize("num,name", [ ["syh123", "syh123"], ["syh456", "syh456"], ["syh789", "syh789"] ]) def test_add(self, num, name): # 點選新增 with allure.step("點選新增"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/button[2]").click() # 新增編號 with allure.step("新增編號"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/div/form/div[1]/div/div[1]/input").send_keys( num) # 填寫名稱 with allure.step("填寫名稱"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/div/form/div[2]/div/div[1]/input").send_keys( name) # 點選上架 with allure.step("點選上架"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[5]/button[2]").click() time.sleep(2) # 顯示等待獲取物件地文字 with allure.step("斷言"): wait = WebDriverWait(self.driver, 10) element = wait.until(EC.presence_of_element_located( (By.CSS_SELECTOR, "h2.el-notification__title"))) assert element.text == "成功" @pytest.mark.parametrize("num,name", [ ["syh123", "syh123"], ["syh456", ""], ["", "syh789"] ]) def test_add_err(self, num, name): # 點選商品列表 with allure.step("點選商品列表"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[1]/div[1]/div/ul/div[3]/li/ul/div[1]/a/li").click() # 點選新增 with allure.step("點選新增"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/button[2]").click() time.sleep(2) # 輸入編號 with allure.step("輸入編號"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/div/form/div[1]/div/div[1]/input").send_keys( num) # 輸入名稱 with allure.step("輸入名稱"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/div/form/div[2]/div/div[1]/input").send_keys( name) # 點選上架 with allure.step("點選上架"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[5]/button[2]").click() # 點選確定 with allure.step("點選確定"): self.driver.find_element(By.CSS_SELECTOR, ".el-button.el-button--default.el-button--small.el-button--primary").click() # 檢視是否新增成功 with allure.step("檢視是否新增成功"): wait = WebDriverWait(self.driver, 10) element = wait.until(EC.presence_of_element_located( (By.CSS_SELECTOR, "h2.el-notification__title"))) # 斷言 assert element.text == "成功" @allure.title("正確地刪除") @pytest.mark.parametrize("num", ["syh123", "syh456", "syh789"]) def test_del(self, num): # 點選商品列表 with allure.step("點選商品列表"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[1]/div[1]/div/ul/div[3]/li/ul/div[1]/a/li").click() # 獲取編號輸入框 with allure.step("獲取編號輸入框"): input = self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/div[2]/input") # 填入編號 with allure.step("填入編號"): input.send_keys(num) # 點選查詢按鈕 with allure.step("點選查詢按鈕"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[1]/button[1]").click() # 點選刪除按鈕 with allure.step("點選刪除按鈕"): self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div[2]/section/div/div[2]/div[3]/table/tbody/tr[1]/td[12]/div/button[2]").click() input.clear() time.sleep(2) with allure.step("斷言"): wait = WebDriverWait(self.driver, 10) element = wait.until(EC.presence_of_element_located( (By.CSS_SELECTOR, "h2.el-notification__title"))) assert element.text == "成功"