Selenium学习(十) selenium IDE命令之 verify系列详解

    技术2023-07-14  92

    目录

    verify系列简介

    相关方法

    官方API

    验证过程

    命令详解


    verify系列简介

    Verify系列是验证,验证目标对象是否一致或不一致。

    无论验证结果成功或失败,均继续执行。

     

    相关方法

    verifyverify checkedverify editableverify element presentverify element not presentverify not checkedverify not editableverify not selected valueverify not textverify selected labelverify selected valueverify textverify titleverify valuewait for element edit

     

    官方API


    verify

    Soft assert that a variable is an expected value. The variable's value will be converted to a string for comparison. The test will continue even if the verify 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).


    verify checked

    Soft assert that a toggle-button (checkbox/radio) has been checked. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify editable

    Soft assert whether the specified input element is editable (e.g., hasn't been disabled). The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify element present

    Soft assert that the specified element is somewhere on the page. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify element not present

    Soft assert that the specified element is not somewhere on the page. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify not checked

    Soft assert that a toggle-button (checkbox/radio) has not been checked. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify not editable

    Soft assert whether the specified input element is not editable (e.g., hasn't been disabled). The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    verify not selected value

    Soft assert that the expected element has not been chosen in a select menu by its option attribute. The test will continue even if the verify fails.

    arguments

    select locator: An element locator identifying a drop-down menu.

    option: An option locator, typically just an option label (e.g. "John Smith").


    verify not text

    Soft assert the text of an element is not present. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    text: The text to use.


    verify selected label

    Soft assert the visible text for a selected option in the specified select element. The test will continue even if the verify 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.


    verify selected value

    Soft assert that the expected element has been chosen in a select menu by its option attribute. The test will continue even if the verify fails.

    arguments

    select locator: An element locator identifying a drop-down menu.

    option: An option locator, typically just an option label (e.g. "John Smith").


    verify text

    Soft assert the text of an element is present. The test will continue even if the verify fails.

    arguments

    locator: An element locator.

    text: The text to use.


    verify title

    Soft assert the title of the current page contains the provided text. The test will continue even if the verify fails.

    arguments

    text: The text to use.

    verify value

    Soft assert 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 continue even if the verify 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.

     

    验证过程

    测试页面代码verify.html

    <!DOCTYPE html> <html> <head> <title>selenium 学习之verify系列 </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> </style> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.bootcss.com/soundmanager2/2.97a.20170601/script/soundmanager2.js"></script> <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 innnerDoms(){ var dom='<span id="innerdomid">我是动态插入的!</span>'; document.getElementById("innerparentsid").innerHTML=dom; } 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 之 verify系列 </h1> <div id="main"> <h3>1、verify </h3> <br/><br/> <h3>2、verify checked、verify not checked </h3> <input type="checkbox" id="check1" >喜欢冰淇淋(id=check1)<br/> <input type="checkbox" id="check2" checked="checked">不喜欢冰淇淋(id=check2)<br><br> <input type="radio" id="check3" name="like" value="bb">篮球<br> <input type="radio" id="check4" name="like" value="bp" checked>排球<br><br> <h3>3、verify element present & verify element not present:</h3> <div id='innerparentsid'></div> <br/><br/> <h3>4、verify editable、verify 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>5、verify not selected value、verify selected value、verify 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>6、verify not text、verify 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>7、verify title </h3> get title and match it! <br/><br/> <h3>8、verify 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" selected="selected">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": "53c2571d-1bd1-4505-b7d1-e01eda57853c", "version": "2.0", "name": "tdst", "url": "http://localhost:8080/aa/verify.html", "tests": [{ "id": "64572b1b-096a-4048-a495-87083231b33b", "name": "Untitled", "commands": [{ "id": "6be71662-f985-4b62-823d-fbdf2aab2b8e", "comment": "", "command": "open", "target": "http://localhost:8080/aa/verify.html", "targets": [], "value": "" }, { "id": "8d568e32-e08c-4fe9-b31f-6745f34c2a2b", "comment": "", "command": "//1、verify", "target": "", "targets": [], "value": "" }, { "id": "624643b1-45e2-450b-b424-a6710a8122b5", "comment": "", "command": "store", "target": "123", "targets": [], "value": "sss" }, { "id": "2c91082f-b764-4c5f-b5ee-4e79fcdbe8ed", "comment": "", "command": "verify", "target": "sss", "targets": [], "value": "123" }, { "id": "d06e00fd-00c0-41fb-b20e-95ed1db28754", "comment": "", "command": "// 2、verify checked & verify not checked", "target": "", "targets": [], "value": "" }, { "id": "b0cbad17-3b8f-430d-b787-7660a10ab16b", "comment": "", "command": "verifyChecked", "target": "id=check1", "targets": [], "value": "" }, { "id": "f510dce0-628d-4a07-8b40-9eda06f23c91", "comment": "", "command": "verifyNotChecked", "target": "id=check1", "targets": [], "value": "" }, { "id": "10968825-5319-4c59-aea7-24dede4219bb", "comment": "", "command": "verifyChecked", "target": "id=check2", "targets": [], "value": "" }, { "id": "e130ce48-1df8-4001-9143-aeda7df81893", "comment": "", "command": "verifyNotChecked", "target": "id=check2", "targets": [], "value": "" }, { "id": "5faf6f7e-3797-4648-a81d-cafffcb52705", "comment": "", "command": "verifyChecked", "target": "id=check3", "targets": [], "value": "" }, { "id": "36095035-0e0b-47c5-bb32-0087aa6e814e", "comment": "", "command": "verifyNotChecked", "target": "id=check3", "targets": [], "value": "" }, { "id": "f8e0cba6-1f3d-4483-b3a0-d3dfd1e5b76c", "comment": "", "command": "verifyChecked", "target": "id=check4", "targets": [], "value": "" }, { "id": "d9da8132-78af-46d8-80f2-9321c31495ec", "comment": "", "command": "verifyNotChecked", "target": "id=check4", "targets": [], "value": "" }, { "id": "1c2d7a3f-7139-48bd-960f-8eb06ea21f0b", "comment": "", "command": "//3、verifyElementNotPresent&verify element not present", "target": "", "targets": [], "value": "" }, { "id": "1d6ad0ed-9ccc-4d12-b906-726ec5171bdc", "comment": "", "command": "verifyElementPresent", "target": "id=innerdomid", "targets": [], "value": "" }, { "id": "b7a8aecb-79db-4684-8d51-3e92681d2ccb", "comment": "", "command": "verifyElementNotPresent", "target": "id=innerdomid", "targets": [], "value": "" }, { "id": "22a413b1-538f-41be-ae2b-6f58b9998992", "comment": "", "command": "executeScript", "target": "innnerDoms()", "targets": [], "value": "" }, { "id": "28dba1bc-db3e-40ee-bc9f-14884da5124a", "comment": "", "command": "verifyElementPresent", "target": "id=innerdomid", "targets": [], "value": "" }, { "id": "b9a8032a-29b3-4291-818c-9c261a39676c", "comment": "", "command": "verifyElementNotPresent", "target": "id=innerdomid", "targets": [], "value": "" }, { "id": "f5ced671-872c-469e-9dc7-ea7364a46bb8", "comment": "", "command": "//4、verifyNotEditable & verifyEditable", "target": "", "targets": [], "value": "" }, { "id": "377c96ea-e88f-44ef-bc57-739bd2551c75", "comment": "", "command": "verifyEditable", "target": "id=ed_0", "targets": [], "value": "" }, { "id": "bf9383a9-7852-43ce-82fb-32d8303617bd", "comment": "", "command": "verifyEditable", "target": "id=ed_1", "targets": [], "value": "" }, { "id": "079d3917-9cc7-4c8f-940d-8146a0b691bd", "comment": "", "command": "verifyEditable", "target": "id=ed_2", "targets": [], "value": "" }, { "id": "2f7176b0-deb8-4dce-aa3c-5838b0053f55", "comment": "", "command": "verifyEditable", "target": "id=ed_3", "targets": [], "value": "" }, { "id": "e687533c-ae9b-4d2b-be2f-58ea121830a9", "comment": "", "command": "verifyEditable", "target": "id=ed_4", "targets": [], "value": "" }, { "id": "d10e3f73-8b1c-4c94-8c5e-47758a549a1d", "comment": "", "command": "verifyNotEditable", "target": "id=ed_0", "targets": [], "value": "" }, { "id": "955b2ce4-06ee-4105-9b43-19dd96613f31", "comment": "", "command": "verifyNotEditable", "target": "id=ed_2", "targets": [], "value": "" }, { "id": "17096111-2178-4721-8b9e-6c5cb8b04f0b", "comment": "", "command": "verifyNotEditable", "target": "id=ed_3", "targets": [], "value": "" }, { "id": "598f26a6-a34d-43b7-8c15-f4810089b26e", "comment": "", "command": "verifyNotEditable", "target": "id=ed_4", "targets": [], "value": "" }, { "id": "57fed1a2-2e33-43b8-ac0e-447915ee63ee", "comment": "", "command": "//5、verifySelectedValue&verify not selected value&verify selected label", "target": "", "targets": [], "value": "" }, { "id": "5dc1ac12-6977-4695-8f01-7e13653103dd", "comment": "", "command": "verifySelectedValue", "target": "id=dp", "targets": [], "value": "volvo" }, { "id": "0b0b28e7-ae7f-4502-98b5-3cfcd897bb61", "comment": "", "command": "verifyNotSelectedValue", "target": "id=dp", "targets": [], "value": "volvo" }, { "id": "72ea5000-5f43-499d-925f-f22126457e23", "comment": "", "command": "verifySelectedValue", "target": "id=dp", "targets": [], "value": "mercedes" }, { "id": "dd0a73d7-45e7-48a3-a855-25eb3a9df73c", "comment": "", "command": "verifyNotSelectedValue", "target": "id=dp", "targets": [], "value": "mercedes" }, { "id": "bd2ea1fa-20ee-43f6-b071-fb63add34bbb", "comment": "", "command": "verifySelectedLabel", "target": "id=dp", "targets": [], "value": "Volvo" }, { "id": "3fb74bd7-9167-4294-ab25-7a86cf4216cf", "comment": "", "command": "verifySelectedLabel", "target": "id=dp", "targets": [], "value": "Mercedes" }, { "id": "15167960-b954-47d9-a1fc-69ce1c13db64", "comment": "", "command": "//6、verifyNotText&verify text", "target": "", "targets": [], "value": "" }, { "id": "fae9a13e-6cab-4549-965a-09094126f3ce", "comment": "", "command": "verifyText", "target": "id=8sp_1", "targets": [], "value": "this is span1" }, { "id": "f0ab8b66-5f78-4a9a-b2c6-eb481a7495e5", "comment": "", "command": "verifyText", "target": "id=8sp_2", "targets": [], "value": "" }, { "id": "53a529e7-149b-488f-9b6a-20d9f45f39c2", "comment": "", "command": "verifyText", "target": "id=8sp_3", "targets": [], "value": "this is a p" }, { "id": "55037f7b-cf7c-4fc6-8824-435257196298", "comment": "", "command": "verifyNotText", "target": "id=8sp_1", "targets": [], "value": "this is span1" }, { "id": "b6e2ab8c-4503-41c8-aea9-5a590d8eaf9c", "comment": "", "command": "verifyNotText", "target": "id=8sp_2", "targets": [], "value": "" }, { "id": "26db9126-b3e3-484e-b0fc-157deedcb832", "comment": "", "command": "verifyNotText", "target": "id=8sp_3", "targets": [], "value": "this is a p" }, { "id": "c629211b-1fa3-4af5-a8d4-ba292bc40acc", "comment": "", "command": "//7、verifyTitle", "target": "", "targets": [], "value": "" }, { "id": "1b6ff40b-921c-456e-b819-d6e025a7ddf8", "comment": "", "command": "verifyTitle", "target": "selenium 学习之verify系列", "targets": [], "value": "" }, { "id": "da968c7c-956e-4b07-b314-a13cbc420050", "comment": "", "command": "verifyTitle", "target": " selenium 学习之verify系列 ", "targets": [], "value": "" }, { "id": "377241a3-f8b3-47eb-acca-32ca0f64af86", "comment": "", "command": "verifyTitle", "target": "asdfasdfasdfasdfa", "targets": [], "value": "" }, { "id": "51cbd910-035e-4df0-8fe7-d8648779679b", "comment": "", "command": "//8、verifyValue", "target": "", "targets": [], "value": "" }, { "id": "fb2a03a0-af02-4ece-b2d8-3dd57edd343a", "comment": "", "command": "verifyValue", "target": "id=vv_1", "targets": [], "value": "this is span" }, { "id": "64cd3aa8-8963-41f7-81cd-569df7b89484", "comment": "", "command": "verifyValue", "target": "id=vv_2", "targets": [], "value": "1" }, { "id": "2bdce68e-4448-4b82-a0f5-a316bd71ac9c", "comment": "", "command": "verifyValue", "target": "id=vv_3", "targets": [], "value": "1" }, { "id": "1d0ba8dc-ed43-42ec-94c3-ae011759ffe9", "comment": "", "command": "verifyValue", "target": "id=vv_4", "targets": [], "value": "mercedes" }, { "id": "5e31bd0e-1ebc-418a-8afb-3aecd621a5f6", "comment": "", "command": "verifyValue", "target": "id=vv_4", "targets": [], "value": "volvo" }, { "id": "cba5992f-bb1d-4049-a7a9-a5381c20d385", "comment": "", "command": "verifyValue", "target": "id=vv_5", "targets": [], "value": "Car" }, { "id": "264b6129-0ab4-49a8-9583-86e78d503a2d", "comment": "", "command": "verifyValue", "target": "id=vv_5x", "targets": [], "value": "off" }, { "id": "5d140f46-7511-4cd8-91e5-c794f80596d2", "comment": "", "command": "verifyValue", "target": "id=vv_5x", "targets": [], "value": "on" }, { "id": "0953560b-5978-4088-8fe0-35be47da6634", "comment": "", "command": "verifyValue", "target": "id=vv_5xx", "targets": [], "value": "on" }, { "id": "4b873711-a024-474b-8e49-e9b71848bbbe", "comment": "", "command": "verifyValue", "target": "id=vv_5xx", "targets": [], "value": "off" }, { "id": "9a5de380-9626-4838-9893-9ac15dad44f9", "comment": "", "command": "verifyValue", "target": "id=vv_6", "targets": [], "value": "on" }, { "id": "4b16e345-54a8-4f3a-b20f-42dfc2ebcebb", "comment": "", "command": "verifyValue", "target": "id=vv_6", "targets": [], "value": "off" }, { "id": "3b2e9ea2-c9c7-4e4e-bd9a-83c7a89dfae2", "comment": "", "command": "verifyValue", "target": "id=vv_6x", "targets": [], "value": "on" }, { "id": "27b331f3-1bac-45ca-b09d-34e777850c6f", "comment": "", "command": "verifyValue", "target": "id=vv_6x", "targets": [], "value": "off" }, { "id": "2cb6026f-98be-4c54-9eea-f598be2fe3c9", "comment": "", "command": "verifyValue", "target": "id=vv_7", "targets": [], "value": "red" }, { "id": "92b4b38c-801f-4448-8cd4-7928e08a4dfc", "comment": "", "command": "verifyValue", "target": "id=vv_8", "targets": [], "value": "blue" }, { "id": "28e48b29-1ab9-44e6-bc07-a8126f57a09f", "comment": "", "command": "verifyValue", "target": "id=vv_9", "targets": [], "value": "on" }, { "id": "d8d45563-2271-49d6-bf9e-7f7c94e09f2b", "comment": "", "command": "verifyValue", "target": "id=vv_9", "targets": [], "value": "off" }, { "id": "66c84c05-3d83-403c-ac5f-94d83b5d91d7", "comment": "", "command": "verifyValue", "target": "id=vv_9x", "targets": [], "value": "on" }, { "id": "0062d3df-2169-48dd-9f99-60f57416066d", "comment": "", "command": "verifyValue", "target": "id=vv_9x", "targets": [], "value": "off" }, { "id": "e277475f-4da1-4711-82e7-0ad42feb4c01", "comment": "", "command": "echo", "target": "this is end", "targets": [], "value": "" }] }], "suites": [{ "id": "51ac09ad-2690-436d-8115-a331c8e25966", "name": "Default Suite", "persistSession": false, "parallel": false, "timeout": 300, "tests": ["64572b1b-096a-4048-a495-87083231b33b"] }], "urls": ["http://localhost:8080/aa/verify.html"], "plugins": [] }

     

    命令详解

    verify 解析:验证变量是否是期望的值

    verify checked 解析:验证单选框或复选框选中

    verify editable 解析:验证输入项是可以编辑 注意: 1、控件界面是否展示与是否可以编辑无关,如果隐藏了但仍旧是可以编辑的状态,那么返回true; 2、非输入控件,返回false;

    verify element present 解析:验证元素是在当前界面上

    verify element not present 解析:验证元素不在当前界面上

    verify not checked 解析:验证单选框或复选框未选中  

    verify not editable 解析:验证输入项不可以编辑 注意: 1、控件界面是否展示与是否可以编辑无关,如果隐藏了但仍旧是不能编辑的状态,那么返回true; 2、非输入控件,返回false;

    verify not selected value 解析:验证下拉框选中的值域传递的值一致  

    verify not text 解析:验证元素的文本与传递的值不一致 注意: 1、该方法执行时会去前后空格;  

    verify selected label 解析:验证下拉框选中的文本是否与传递的一致

    verify selected value 解析:验证下拉框选中的值域传递的值一致  

    verify text 解析:验证元素的文本与传递的值不一致 注意: 1、该方法执行时会去前后空格;

    verify title 解析:获得当前界面标题并判断与传递的值一致 注意:

    verify value 解析:判断元素的值与传递的值一致 注意: 1、当元素没有value时,如span,返回false; 2、对于单选框、复选框的,如果有value属性,就通过value属性判断,与是否选中无关; 3、对于单选框、复选框的,如果没有value属性,该方法返回的是on,与是否选中无关,与api描述有出入;

    Processed: 0.011, SQL: 9