Junit测试+selenium录制自动化脚本
程序员文章站
2022-04-27 17:29:00
...
单元测试(使用Junit4.11)
测试图片上传模块:
@Test
public void insert() {
Image image=new Image();
image.setImageName("测试插入图片");
image.setUploadTime("20-09-04 12:00:00");
image.setSize(1200818);
image.setMd5("2553a6426fc4c5b10a20f4de5a110421");
image.setContentType("image/jpeg");
image.setPath("C:\\Users\\七夜\\Desktop\\1.PNG");
ImageDao imageDao=new ImageDao();
imageDao.insert(image);
}
测试结果:
测试图片删除模块:
@Test
public void delete() {
ImageDao imageDao = new ImageDao();
boolean flag = imageDao.delete(3);
System.out.println(flag);
}
selenium录制自动化脚本
import unittest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestYunPan(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.vars = {}
def tearDown(self):
self.driver.quit()
def test_yunpan(self):
self.driver.get("http://localhost:8080/java_image_server/index.html")
self.driver.set_window_size(909, 629)
time.sleep(2)
self.driver.find_element(By.NAME, "filename").click()
time.sleep(2)
self.driver.find_element(By.NAME, "filename").send_keys("C:\\fakepath\\1.PNG")
self.driver.find_element(By.CSS_SELECTOR, ".am-form-group:nth-child(2) > .am-form-field").click()
time.sleep(2)
self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(3) > .am-btn").click()
time.sleep(2)
assert self.driver.switch_to.alert.text == "删除成功"
time.sleep(2)
上一篇: 系统学习---- Linux进程管理
下一篇: ubuntu18.04 配置nginx