主题
firefox selenium ide
官方文档:https://www.selenium.dev/selenium-ide/docs/en/introduction/getting-started
打开浏览器扩展后

4个选项
- 在新项目中录制新测试
- 打开已有项目
- 创建新项目
- 关闭
开始录制
创建项目界面中输入项目的名称:diyai.cn
base url: https://diyai.cn


单击START RECORDING
按钮,将开始录制。
Selenium IDE将打开一个新的浏览器窗口,并以刚才填写的初始URL作为浏览器打开的页面地址,同时在浏览器窗口的右下方,可以看到Selenium IDE录制窗口,表示该浏览器窗口正处于录制状态
停止录制

设置测试用例名
后保存

录制结束后,在Command表格中,可以看到所有浏览器的操作,在录制时都转换成了Selenium命令,存放在Command表格中。
Command表格,由3列信息组成。
Command:表示要执行的操作是什么。
Target:参数1,操作的界面元素
Value:参数2,操作值
回放脚本
此时点击执行
按钮会打开新的浏览器窗口执行脚本的内容
保存回放文件
发现Bug时,可创建Bug重现脚本以附件
的形式提交给开发人员
回放.side
文件内容如下
json
{
"id": "95ddce3d-c433-43b7-804a-a230108c7258",
"version": "2.0",
"name": "diyai.cn",
"url": "https://diyai.cn",
"tests": [{
"id": "4e8f6395-e863-4600-b325-6e2a638a9749",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "a7de7d9d-b196-4546-9287-d53d31923883",
"comment": "",
"command": "setWindowSize",
"target": "1512x897",
"targets": [],
"value": ""
}, {
"id": "751bdd2f-39af-4726-82fc-dac89c9fd933",
"comment": "",
"command": "click",
"target": "css=.VPLink:nth-child(2) > span",
"targets": [
["css=.VPLink:nth-child(2) > span", "css:finder"],
["xpath=//div[@id='app']/div/header/div/div/div/div[2]/div/nav/a/span", "xpath:idRelative"],
["xpath=//nav/a/span", "xpath:position"],
["xpath=//span[contains(.,'登录')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "bf4e99e1-82a2-4921-8fd9-8fecb3f4a490",
"comment": "",
"command": "click",
"target": "id=btw-modal",
"targets": [
["id=btw-modal", "id"],
["css=#btw-modal", "css:finder"],
["xpath=//div[@id='btw-modal']", "xpath:attributes"],
["xpath=//div[@id='btw-modal-wrap']/div[2]", "xpath:idRelative"],
["xpath=//div[2]/div[2]", "xpath:position"]
],
"value": ""
}, {
"id": "29304b49-f7d0-4a4a-bc28-158a21805a9a",
"comment": "",
"command": "click",
"target": "id=btw-modal-close-btn",
"targets": [
["id=btw-modal-close-btn", "id"],
["css=#btw-modal-close-btn", "css:finder"],
["xpath=//span[@id='btw-modal-close-btn']", "xpath:attributes"],
["xpath=//div[@id='btw-modal']/span", "xpath:idRelative"],
["xpath=//div[2]/span", "xpath:position"],
["xpath=//span[contains(.,'×')]", "xpath:innerText"]
],
"value": ""
}]
}],
"suites": [{
"id": "1bb98ed2-a848-4a6c-9edf-a0c4f3c78e6d",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["697a856a-3e9e-4c4d-af70-2f985eeb027d"]
}],
"urls": ["https://diyai.cn/"],
"plugins": []
}
添加测试验证

Command:下拉选择 asset element present
Target : 选择元素
再次执行回放脚本,查看执行日志是成功的
导出脚本

选择python pytest,导出的脚本内容为
python
# Generated by Selenium IDE
import pytest
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 TestDemo1():
def setup_method(self, method):
self.driver = webdriver.Firefox()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_demo1(self):
self.driver.get("https://diyai.cn/")
self.driver.set_window_size(1512, 897)
self.driver.find_element(By.CSS_SELECTOR, ".VPLink:nth-child(2) > span").click()
self.driver.find_element(By.ID, "btw-modal").click()
self.driver.find_element(By.ID, "btw-modal-close-btn").click()
elements = self.driver.find_elements(By.CSS_SELECTOR, ".VPLink:nth-child(3) > span")
assert len(elements) > 0