目录
assert系列简介
使用断言,测试用例将会在断言失败后停止运行
优点:可以直接直接了当的看到检查是否通过
缺点:若检查失败,后续的检查不会被执行,无法收集检查的结果状态
相关方法
assert
assert alert
assert checked
assert confirmation
assert editable
assert element present
assert element not present
assert not checked
assert not editable
assert not selected value
assert not text
assert prompt
assert selected value
assert selected label
assert text
assert title
assert value
官方API
assert
Check that a variable is an expected value. The variable's value will be converted to a string for comparison. The test will stop if the assert fails.
arguments
-
variable name: The name of a variable without brackets.
-
expected value: The result you expect a variable to contain (e.g., true, false, or some other value).
assert alert
Confirm that an alert has been rendered with the provided text. The test will stop if the assert fails.
arguments
- alert text: text to check
assert checked
Confirm that the target element has been checked. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert confirmation
Confirm that a confirmation has been rendered. The test will stop if the assert fails.
arguments
- text: The text to use.
assert editable
Confirm that the target element is editable. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert element present
Confirm that the target element is present somewhere on the page. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert element not present
Confirm that the target element is not present anywhere on the page. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert not checked
Confirm that the target element has not been checked. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert not editable
Confirm that the target element is not editable. The test will stop if the assert fails.
arguments
- locator: An element locator.
assert not selected value
Confirm that the value attribute of the selected option in a dropdown element does not contain the provided value. The test will stop if the assert fails.
arguments
-
select locator: An element locator identifying a drop-down menu.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert not text
Confirm that the text of an element does not contain the provided value. The test will stop if the assert fails.
arguments
-
locator: An element locator.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert prompt
Confirm that a JavaScript prompt has been rendered. The test will stop if the assert fails.
arguments
- text: The text to use.
assert selected value
Confirm that the value attribute of the selected option in a dropdown element contains the provided value. The test will stop if the assert fails.
arguments
-
select locator: An element locator identifying a drop-down menu.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert selected label
Confirm that the label of the selected option in a dropdown element contains the provided value. The test will stop if the assert fails.
arguments
-
select locator: An element locator identifying a drop-down menu.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert text
Confirm that the text of an element contains the provided value. The test will stop if the assert fails.
arguments
-
locator: An element locator.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert title
Confirm the title of the current page contains the provided text. The test will stop if the assert fails.
arguments
- text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
assert value
Confirm the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not. The test will stop if the assert fails.
arguments
-
locator: An element locator.
-
text: An exact string match. Support for pattern matching is in the works. See https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
验证过程
测试页面代码assert.html
<!DOCTYPE html>
<html>
<head>
<title>selenium 学习之assert系列 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
</style>
<script type="text/javascript">
function myFunction(){
var x;
var person=prompt("请输入你的名字","Harry Potter");
if (person!=null && person!=""){
x="你好 " + person + "! 今天感觉如何?";
document.getElementById("demo").innerHTML=x;
}
else{
x="收到了cancle,呜呜呜~~"+person;
document.getElementById("demo").innerHTML=x;
}
}
function myAlert(){
alert("你好,我是一个警告框!");
}
function disp_confirm()
{
var r=confirm("Press a button")
if (r==true)
{
document.getElementById("disp_confirm").innerHTML='点了确定';
}
else
{
document.getElementById("disp_confirm").innerHTML='点了取消';
}
}
</script>
</head>
<h1>selenium test 之 assert系列 </h1>
<div id="main">
<h3>1、assert value: </h3>
after store then assert value!
<br/><br/>
<h3>2、assert alert:点击触发alert! </h3>
<input type="button" id="ass_alert" onclick="myAlert()" value="显示alert" />
<br/><br/>
<h3>3、assert checked、assert not checked </h3>
<input type="checkbox" id="check1" >喜欢冰淇淋<br/>
<input type="checkbox" id="check2" checked="checked">不喜欢冰淇淋<br><br>
<input type="radio" id="check3" name="like" value="bb">篮球<br>
<input type="radio" id="check4" name="like" value="bp" checked>排球<br><br>
<br/><br/>
<h3>4、assert confirm: </h3>
<input type="button" onclick="disp_confirm()" id="ass_conf" value="Display a confirm box" />
<p id="disp_confirm"></p>
<br/><br/>
<h3>5、assert editable、assert not editable </h3>
<input type="text" id="ed_0" /><br/>
<input type="text" id="ed_1" readonly /><br/>
<input type="text" id="ed_2" disabled="disabled"/><br/>
<input type="text" id="ed_3" style="display:none;" value="dis_none"/>
<span id="ed_4"></span>
<br/><br/>
<h3>6、assert element present、assert element not present </h3>
<span id="sp_1">this is span1</span>
<input type="text" id="sp_2" value="434423" /><br/>
<br/><br/>
<h3>7、assert not selected value、assert selected value、assert selected label: </h3>
<select id='dp'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br/><br/>
<h3>8、assert not text、assert text: </h3>
<span id="8sp_1">this is span1</span><br/>
<input type="text" id="8sp_2" value="434423" /><br/>
<p id="8sp_3">this is a p</p>
<br/><br/>
<h3>9、assert prompt:</h3>
<input type="button" id="ass_pro" onclick="myFunction()" value="显示prompt" />
<p id="demo"></p>
<br/><br/>
<h3>10、assert title: </h3>
get title and match it!
<br/><br/>
<h3>11、assert value: </h3>
<span id="vv_1">this is span</span><br/>
<input type="text" id="vv_2" readonly value="1" /><br/>
<input type="text" id="vv_3" value="1" /><br/>
<br/><br/>
下拉框<select id='vv_4'>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br/><br/>
交通工具复选:
<input type="checkbox" id="vv_5" name="vehicle" value="Car"/>Car<br/>
<input type="checkbox" id="vv_5x" name="vehicle"/>Car<br/>
<input type="checkbox" id="vv_5xx" />Car<br/>
<input type="checkbox" id="vv_6" name="vehicle" value="Bike" checked>Bike<br/>
<input type="checkbox" id="vv_6x" name="vehicle" checked>Bus<br/><br/>
单选颜色:
<input type="radio" id="vv_7" name="colors" value="red">红色<br>
<input type="radio" id="vv_8" name="colors" value="blue" checked>蓝色1<br><br>
<input type="radio" id="vv_9" name="colors2">蓝色修奥<br>
<input type="radio" id="vv_9x" name="colors2" checked>蓝色恶魔<br>
</div>
</body>
</html>
selenium IDE脚本:




side文件代码
{
"id": "ebdea160-8f6b-41a7-a47b-64f23f9c4e46",
"version": "2.0",
"name": "2",
"url": "http://localhost:8080/aa/assert.html",
"tests": [{
"id": "45f351cf-01a2-4f84-90c0-0ea006d54623",
"name": "1",
"commands": [{
"id": "62556200-c0f2-424b-989d-d97f7055375d",
"comment": "",
"command": "open",
"target": "http://localhost:8080/aa/assert.html",
"targets": [],
"value": ""
}, {
"id": "e5c7ce53-2849-43f6-8764-c7c9a35d0058",
"comment": "",
"command": "setWindowSize",
"target": "1187x728",
"targets": [],
"value": ""
}, {
"id": "9ad50e0a-f471-46a0-8955-7544698127ef",
"comment": "",
"command": "//1、assert value",
"target": "",
"targets": [],
"value": ""
}, {
"id": "e3e95115-4716-4e0c-b7ac-9ec9c020cc1c",
"comment": "",
"command": "store",
"target": "8",
"targets": [],
"value": "as_var"
}, {
"id": "4abdf07d-7e5f-40a8-9d02-2ee520c336fe",
"comment": "",
"command": "store",
"target": " 8 ",
"targets": [],
"value": "as_var2"
}, {
"id": "2fabc0c0-24ac-4d01-998e-08c60115ea53",
"comment": "",
"command": "assert",
"target": "as_var",
"targets": [],
"value": "8"
}, {
"id": "7657f451-15b0-4a1c-acfe-72bc00aebe61",
"comment": "",
"command": "assert",
"target": "as_var2",
"targets": [],
"value": "8"
}, {
"id": "3fd32bb7-4fb0-44d8-9815-8f046006c2d2",
"comment": "",
"command": "//2、assert alert",
"target": "",
"targets": [],
"value": ""
}, {
"id": "567ffc90-6d84-4ba0-9fdc-498e150819fd",
"comment": "",
"command": "click",
"target": "id=ass_alert",
"targets": [
["css=input:nth-child(2)", "css:finder"],
["xpath=//input[@value='显示alert']", "xpath:attributes"],
["xpath=//div[@id='main']/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": ""
}, {
"id": "9dbeb8a3-eb7d-4366-a58a-15ef0d427444",
"comment": "",
"command": "assertAlert",
"target": "你好,我是一个警告框! ",
"targets": [],
"value": ""
}, {
"id": "4a4e8e8f-0b24-4f19-84f3-2ce8103355eb",
"comment": "",
"command": "//3、assert checked、assert not checked",
"target": "",
"targets": [],
"value": ""
}, {
"id": "2b783e47-f48b-475d-832a-a749af999bab",
"comment": "",
"command": "assertNotChecked",
"target": "id=check1",
"targets": [],
"value": ""
}, {
"id": "82ba871b-337b-4c3f-91d9-6231db9dc8d7",
"comment": "falil",
"command": "//assertChecked",
"target": "id=check1",
"targets": [],
"value": ""
}, {
"id": "4f34f759-8040-415b-ba59-b58009f2fb72",
"comment": "",
"command": "assertChecked",
"target": "id=check2",
"targets": [
["id=check1", "id"],
["css=#check1", "css:finder"],
["xpath=//input[@id='check1']", "xpath:attributes"],
["xpath=//div[@id='main']/input[2]", "xpath:idRelative"],
["xpath=//input[2]", "xpath:position"]
],
"value": ""
}, {
"id": "3f724edc-ee5a-424e-8bd7-c091301edbee",
"comment": "fail",
"command": "//assertChecked",
"target": "id=check3",
"targets": [],
"value": ""
}, {
"id": "b77ab14e-3c67-410e-a123-007812b526a1",
"comment": "",
"command": "assertChecked",
"target": "id=check4",
"targets": [
["id=check1", "id"],
["css=#check1", "css:finder"],
["xpath=//input[@id='check1']", "xpath:attributes"],
["xpath=//div[@id='main']/input[2]", "xpath:idRelative"],
["xpath=//input[2]", "xpath:position"]
],
"value": ""
}, {
"id": "05049782-ac80-4878-a47a-8126690793d6",
"comment": "",
"command": "assertNotChecked",
"target": "id=check3",
"targets": [],
"value": ""
}, {
"id": "711f4a21-af75-49fd-bc51-be961751d03b",
"comment": "fail",
"command": "//assertNotChecked",
"target": "id=check4",
"targets": [],
"value": ""
}, {
"id": "2f7aa150-5be7-4182-8af2-7eac21f98ef5",
"comment": "",
"command": "//4、assert confirm",
"target": "",
"targets": [],
"value": ""
}, {
"id": "020e62c8-64ae-4207-9092-aa972d5a15b6",
"comment": "",
"command": "//runScript",
"target": "disp_confirm()",
"targets": [],
"value": ""
}, {
"id": "8617e492-c7d6-412b-8223-bfa093559e27",
"comment": "",
"command": "click",
"target": "id=ass_conf",
"targets": [],
"value": ""
}, {
"id": "2847d6f1-91bc-4f2f-bc94-db288c7d7e88",
"comment": "",
"command": "assertConfirmation",
"target": "Press a button",
"targets": [],
"value": ""
}, {
"id": "cefda854-6b9a-4f53-8e86-d72fe06194e5",
"comment": "",
"command": "//5、assert editable、assert not editable",
"target": "",
"targets": [],
"value": ""
}, {
"id": "c06b1579-9e11-45ea-b51d-c130c5cd5942",
"comment": "",
"command": "assertEditable",
"target": "id=ed_0",
"targets": [
["id=ed_1", "id"],
["css=#ed_1", "css:finder"],
["xpath=//input[@id='ed_1']", "xpath:attributes"],
["xpath=//div[@id='main']/input[5]", "xpath:idRelative"],
["xpath=//input[5]", "xpath:position"]
],
"value": ""
}, {
"id": "0db92055-89a3-4b37-a98f-78b8c1b0b87d",
"comment": "fail",
"command": "//assertEditable",
"target": "id=ed_1",
"targets": [],
"value": ""
}, {
"id": "aa8095f2-482b-490a-98b7-61fb947cc598",
"comment": "",
"command": "assertNotEditable",
"target": "id=ed_1",
"targets": [],
"value": ""
}, {
"id": "0bdb954b-493d-4774-a575-415dcb524f37",
"comment": "fail",
"command": "//assertEditable",
"target": "id=ed_2",
"targets": [],
"value": ""
}, {
"id": "455086d1-adb1-44d2-ac1a-bcf5bb0502ae",
"comment": "",
"command": "assertEditable",
"target": "id=ed_3",
"targets": [
["id=ed_1", "id"],
["css=#ed_1", "css:finder"],
["xpath=//input[@id='ed_1']", "xpath:attributes"],
["xpath=//div[@id='main']/input[5]", "xpath:idRelative"],
["xpath=//input[5]", "xpath:position"]
],
"value": ""
}, {
"id": "09bba335-79cf-4bc6-a338-08826b9d5965",
"comment": "fail",
"command": "//assertEditable",
"target": "id=ed_4",
"targets": [],
"value": ""
}, {
"id": "ab440add-7d6d-4a3b-8e80-ed7414f48a14",
"comment": "fail",
"command": "//assertNotEditable",
"target": "id=ed_4",
"targets": [],
"value": ""
}, {
"id": "f780e704-55a4-472c-b8a5-1b786b9abb4a",
"comment": "",
"command": "//6、assert element present、assert element not present",
"target": "",
"targets": [],
"value": ""
}, {
"id": "30f4ec09-2a0f-497e-b63b-f8e42dadd61b",
"comment": "",
"command": "assertElementPresent",
"target": "id=sp_1",
"targets": [
["id=sp_1", "id"],
["xpath=//span[@id='sp_1']", "xpath:attributes"],
["xpath=//div[@id='main']/span", "xpath:idRelative"],
["xpath=//div[3]/span", "xpath:position"],
["xpath=//span[contains(.,'this is span1')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "c307d2dc-a9d2-4a0e-bc68-cbdc7b573268",
"comment": "",
"command": "assertElementPresent",
"target": "id=sp_2",
"targets": [
["id=sp_1", "id"],
["xpath=//span[@id='sp_1']", "xpath:attributes"],
["xpath=//div[@id='main']/span", "xpath:idRelative"],
["xpath=//div[3]/span", "xpath:position"],
["xpath=//span[contains(.,'this is span1')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "b530a4c5-d898-419e-b535-7e8307102b39",
"comment": "fail",
"command": "//assertElementNotPresent",
"target": "id=sp_1",
"targets": [],
"value": ""
}, {
"id": "b8b5d323-4cca-4efb-97c1-585bc15ae032",
"comment": "",
"command": "assertElementNotPresent",
"target": "id=sp_3",
"targets": [
["id=sp_2", "id"],
["xpath=//span[@id='sp_2']", "xpath:attributes"],
["xpath=//div[@id='main']/span[2]", "xpath:idRelative"],
["xpath=//span[2]", "xpath:position"],
["xpath=//span[contains(.,'this is span2')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "8649ea30-0497-4426-9112-0acdc86abbf1",
"comment": "",
"command": "//7、assert not selected value、assert selected value、assert selected label",
"target": "",
"targets": [],
"value": ""
}, {
"id": "14439daa-25a9-4817-b42f-27fa25bc1a60",
"comment": "",
"command": "type",
"target": "id=dp",
"targets": [],
"value": "saab"
}, {
"id": "82fb3921-c611-4cbe-8916-f283cb1e5f0e",
"comment": "",
"command": "assertSelectedValue",
"target": "id=dp",
"targets": [],
"value": "saab"
}, {
"id": "1e06d476-189e-4f49-95e3-467183bc70c3",
"comment": "",
"command": "assertNotSelectedValue",
"target": "id=dp",
"targets": [],
"value": "mercedes"
}, {
"id": "339cf665-ad17-487e-afa1-76c65f3f56a7",
"comment": "",
"command": "assertSelectedLabel",
"target": "id=dp",
"targets": [],
"value": "Saab"
}, {
"id": "a281180f-1406-415a-93d8-8448d99b588d",
"comment": "fail",
"command": "//assertSelectedLabel",
"target": "id=dp",
"targets": [],
"value": "saab"
}, {
"id": "a7ec3fc6-826c-4304-93b7-21c1f1f23cfe",
"comment": "fail",
"command": "//assertSelectedLabel",
"target": "id=dp",
"targets": [],
"value": "volvo"
}, {
"id": "8332d053-8048-4f92-96e2-b36ac63b42b0",
"comment": "",
"command": "//8、assert not text、assert text",
"target": "",
"targets": [],
"value": ""
}, {
"id": "c905f63a-9c8e-4cf3-b81e-4207007e5b95",
"comment": "",
"command": "assertText",
"target": "id=8sp_1",
"targets": [],
"value": "this is span1"
}, {
"id": "e29d1266-2c3a-4ca2-b55d-98defe591d20",
"comment": "fail",
"command": "//assertText",
"target": "id=8sp_2",
"targets": [],
"value": "434423"
}, {
"id": "0be461db-6123-4a97-97e3-ded5c71ebd8a",
"comment": "",
"command": "assertText",
"target": "id=8sp_3",
"targets": [],
"value": "this is a p"
}, {
"id": "ff4a8bda-6915-456b-a8ef-b8f912a11c95",
"comment": "fail",
"command": "//assertText",
"target": "id=8sp_1",
"targets": [],
"value": "is is spa"
}, {
"id": "ddcabdff-70a3-49a5-8a0d-8b78f68535c1",
"comment": "fail",
"command": "//assertText",
"target": "id=8sp_1",
"targets": [],
"value": ">>this is span1111"
}, {
"id": "fedf1fc4-b823-44f6-bb31-97d57e010e73",
"comment": "fail",
"command": "//assertText",
"target": "id=8sp_3",
"targets": [],
"value": "sp_3"
}, {
"id": "4a63e3f9-b922-4b24-b5dd-453c3b2d9e8e",
"comment": "",
"command": "//9、assert prompt:",
"target": "",
"targets": [],
"value": ""
}, {
"id": "850d811e-3479-4e54-b5e0-24ae81834c5e",
"comment": "",
"command": "click",
"target": "id=ass_pro",
"targets": [],
"value": ""
}, {
"id": "f0de1514-0c47-49a7-bf10-7a517e1a2ef2",
"comment": "",
"command": "assertPrompt",
"target": "请输入你的名字",
"targets": [],
"value": ""
}, {
"id": "8641c8df-f611-43df-937f-74f7124dfbf6",
"comment": "",
"command": "//10、assert title",
"target": "",
"targets": [],
"value": ""
}, {
"id": "f5f98fc5-70a5-4326-9784-b3582c75f6bb",
"comment": "",
"command": "assertTitle",
"target": "selenium 学习之assert系列",
"targets": [],
"value": ""
}, {
"id": "87ada279-b23c-4a72-9edd-9ea154681648",
"comment": "",
"command": "assertTitle",
"target": " selenium 学习之assert系列 ",
"targets": [],
"value": ""
}, {
"id": "ecfc3b36-f24f-4646-a87f-3a2699ef24d7",
"comment": "",
"command": "//11、assert value",
"target": "",
"targets": [],
"value": ""
}, {
"id": "d359742a-fa03-47d2-ac11-e08e0aade20b",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_1",
"targets": [],
"value": "this is span"
}, {
"id": "6c8383ed-4d74-4ff5-941b-25d9405814b3",
"comment": "",
"command": "assertValue",
"target": "id=vv_2",
"targets": [],
"value": "1"
}, {
"id": "d7657ace-3c01-435d-bdd7-9d950e2b2a17",
"comment": "",
"command": "type",
"target": "id=vv_3",
"targets": [],
"value": "33"
}, {
"id": "ee9fe366-6b50-441d-ad90-ad155e69d111",
"comment": "",
"command": "assertValue",
"target": "id=vv_3",
"targets": [],
"value": "33"
}, {
"id": "c4efbc67-a9c9-48c2-b0d9-b8ada9c431ba",
"comment": "",
"command": "type",
"target": "id=vv_4",
"targets": [],
"value": "audi"
}, {
"id": "db6d1f0a-69cb-4f9e-a1c2-3be527c72ab6",
"comment": "",
"command": "assertValue",
"target": "id=vv_4",
"targets": [],
"value": "audi"
}, {
"id": "06e61758-41d0-43c9-90fc-cff5f448ee8c",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_4",
"targets": [],
"value": "mercedes"
}, {
"id": "e6578699-a93e-4621-94e5-2af67752c34b",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_5",
"targets": [],
"value": "on"
}, {
"id": "294ffed1-81f8-4753-ad89-b61615715304",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_5",
"targets": [],
"value": "off"
}, {
"id": "a6b0fa21-5006-4be1-b046-c5378808d528",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_5x",
"targets": [],
"value": "off"
}, {
"id": "ca8968e3-06a4-49fc-8984-226a70f85c7b",
"comment": "fail",
"command": "//assertValue",
"target": "id=vv_5x",
"targets": [],
"value": "off"
}, {
"id": "c529d539-7b6d-43f1-81e7-6852e17ef98d",
"comment": "",
"command": "assertValue",
"target": "id=vv_6",
"targets": [],
"value": "Bike"
}, {
"id": "bdc5ef48-3341-49eb-a43c-10bb019f20bf",
"comment": "",
"command": "assertValue",
"target": "id=vv_6x",
"targets": [],
"value": "on"
}, {
"id": "38071286-911d-4f52-b323-de9a1dcabaae",
"comment": "",
"command": "assertValue",
"target": "id=vv_7",
"targets": [],
"value": "red"
}, {
"id": "3dc4aae9-9137-4d20-b20d-07f4df0c38b1",
"comment": "",
"command": "assertValue",
"target": "id=vv_8",
"targets": [],
"value": "blue"
}, {
"id": "7b0aac5d-12f6-400d-9bb0-e85a6eaa4a3f",
"comment": "",
"command": "assertValue",
"target": "id=vv_9",
"targets": [],
"value": "on"
}, {
"id": "eb35b6e5-1a52-4021-a9eb-11a1bf88c3f3",
"comment": "",
"command": "assertValue",
"target": "id=vv_9x",
"targets": [],
"value": "on"
}, {
"id": "c3e9ea1c-cb0a-4203-a686-026f1b4bd89d",
"comment": "",
"command": "",
"target": "",
"targets": [],
"value": ""
}]
}],
"suites": [{
"id": "cfbb44a9-df94-4d80-a610-b5fc296d98ae",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["45f351cf-01a2-4f84-90c0-0ea006d54623"]
}],
"urls": ["https://www.baidu.com/", "http://localhost:8080/aa/assert.html"],
"plugins": []
}
小结
assert
解析:断言一个变量是否是期望的值,比较是按照字符串进行比较。
注意:
1、使用前必须定义变量;
2、字符串比较前,ide会自动去前后空格;
assert alert
解析:断言alert对话框是否已渲染过,并判断传递的参数与alert对话框的文本是否一致。
注意:比较文本是否一致,ide会自动去前后空格;
assert checked
解析:断言复选框、单选框选中
assert confirmation
解析:断言确认对话框,是否渲染,并判断传递的参数与confirm对话框的文本是否一致。
注意:只要满足以上两个条件即可,对话框选择确定后取消均无所谓。
assert editable
解析:断言目标元素是否可以编辑。
注意:非编辑组件调用会出错,如span。
assert element present
解析:断言组件是否在当前界面上。
注意:该方法使用的时候,只是判断瞬时界面状态,家如js中有个innerHTML方法向界面添加组件A,而调用的方法正好是验证是否当前界面有组件A,那么innerHTML完成后是可以判断有,如果js未执行完,那可能判断没有,这种动态添加的需要验证,可以搭配wait系列一些使用。
assert element not present
解析:断言组件是否不在当前界面上。
assert not checked
解析:断言复选框、单选框未选中
assert not editable
解析:断言目标元素是否不编辑。
注意:非编辑组件调用会出错,如span。
assert not selected value
解析:断言下拉框组件未选中(某个)值。
注意:判断的时候是按照option的value进行判断。
assert not text
解析:断言元素不包含(某个)值。
注意:验证发现,并非api里面提的包含,而是判断是否相同。
assert prompt
解析:断言输入对话框是否已经渲染,并判断传递的参数与prompt对话框的第一个参数(标题)是否一致。
assert selected value
解析:断言下拉框组件选中(某个)值。
注意:判断的时候是按照option的value进行判断。
assert selected label
解析:断言下拉框组件选中(某个)label。
注意:判断的时候是按照option的显示值判断,即下拉框展示的文字,而非value。
assert text
解析:断言元素包含(某个)值。
注意:验证发现,并非api里面提的包含,而是判断是否相同。
assert title
解析:断言当前界面的title是否与参数一致。
注意:判断的时候,ide方法会自动去前后空格。
assert value
解析:断言输入控件的值与参数是否一致。
注意:
1、判断逻辑是,只判断控件的value值域参数是否一致;
2、官网api中展示的,对于checkbox、radio控件,获得的值是on或off,具体取决与控件是否选中,但从验证的结果来看,并非如此。如果这两种控件有value,那么该命令获得的value一直是空间的value;假如控件无value情况下,该命令获得的value一直是on,跟是否选中无任何关系。
本文详细介绍了Selenium IDE中的assert系列命令,包括assert的各种变体,如assert alert、assert checked等,用于在自动化测试中验证元素状态、提示框文本等。文章还列举了每个命令的参数和使用注意事项,帮助理解它们在测试流程中的作用。
1395

被折叠的 条评论
为什么被折叠?



