ui自动化测试,测试项目https://thingsboard.hogwarts.ceshiren.com/,账户是1945075385@qq.com密码hogwarts,请测试设备增删改查,用python实现
时间: 2024-06-08 07:07:32 浏览: 157
好的,这个测试场景我可以用 Python 的 selenium 库进行自动化测试。以下是大致的测试代码:
```python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# 登录账户
driver = webdriver.Chrome()
driver.get("https://thingsboard.hogwarts.ceshiren.com/")
elem = driver.find_element_by_name("username")
elem.send_keys("1945075385@qq.com")
elem = driver.find_element_by_name("password")
elem.send_keys("hogwarts")
elem.send_keys(Keys.RETURN)
time.sleep(5)
# 新增设备
driver.get("https://thingsboard.hogwarts.ceshiren.com/dashboard/3f7d7b20-7b43-11eb-bd5a-3f8ae6b9bcbc")
elem = driver.find_element_by_class_name("add-button")
elem.click()
time.sleep(1)
elem = driver.find_element_by_class_name("tb-create-entity-type-select")
elem.click()
time.sleep(1)
elem = driver.find_element_by_xpath("//div[@class='tb-create-entity-type-select']/div[2]/div[1]/div[1]")
elem.click()
time.sleep(1)
elem = driver.find_element_by_class_name("tb-create-entity-form")
elem = elem.find_element_by_xpath("//input[@placeholder='Device name']")
elem.send_keys("Test Device")
elem = driver.find_element_by_xpath("//input[@placeholder='Serial number']")
elem.send_keys("123456")
elem = driver.find_element_by_class_name("tb-create-entity-footer")
elem = elem.find_element_by_xpath("//button[@type='submit']")
elem.click()
time.sleep(5)
# 修改设备
elem = driver.find_element_by_xpath("//span[text()='Test Device']")
elem.click()
time.sleep(1)
elem = driver.find_element_by_xpath("//input[@name='name']")
elem.clear()
elem.send_keys("New Test Device")
elem = driver.find_element_by_xpath("//input[@name='type']")
elem.clear()
elem.send_keys("New Test Type")
elem = driver.find_element_by_xpath("//input[@name='key']")
elem.clear()
elem.send_keys("New Test Key")
elem = driver.find_element_by_xpath("//button[@type='submit']")
elem.click()
time.sleep(5)
# 删除设备
elem = driver.find_element_by_xpath("//span[text()='New Test Device']")
elem.click()
time.sleep(1)
elem = driver.find_element_by_class_name("tb-delete-entity-button")
elem.click()
time.sleep(1)
elem = driver.find_element_by_xpath("//button[text()='Delete']")
elem.click()
time.sleep(5)
# 关闭浏览器
driver.close()
```
需要注意的是,我使用的是 Chrome 浏览器,所以需要下载对应版本的 chromedriver 并放在系统环境变量中。另外,测试过程中需要等待页面加载,所以我使用了 time.sleep() 函数来进行等待。如果网速较快,可以适当减少等待时间。
阅读全文