"verifyAttribute" and "assertAttribute" commands are useful for verification of values of an attribute of any node on the page of software web application. You can check value of an attributes like class, title, id, name, type, etc.. I got many questions about "Difference between assert and verify in selenium with example" so i will describe
that difference in this post too. Before using both these commands, You must have to read How to build XPath of an element and How to build CSS path of an element articles to be aware about it.
"verifyAttribute" Command
"verifyAttribute" command will just check and verify the value of specified attribute. If found correct value on specified attribute then it will be pass and selenium software testing tool will execute next immediate command. If found incorrect value then selenium software testing tool will return error like "[error] Actual value 'search' did not match 'search1'" and will execute next immediate command.
"assertAttribute" Command
"assertAttribute" command works same as "verifyAttribute" command but only one difference between "assert" and "verify" in selenium is - if "assert" command will fail then selenium software testing tool will not execute next command(stop execution) and if "verify" command will fail then selenium will execute next command(not stop execution).
New Test | ||
Command | Target | Value |
open | http://www.wikipedia.org/ | |
verifyAttribute | css=input + input@id | searchInput |
assertAttribute | css=input + input@id | searchInput |
verifyAttribute | css=input + select@name | language |
verifyAttribute | xpath=//div[2]@class | central-featured |
verifyAttribute | xpath=//input[@type='search'] @name | search1 |
assertAttribute | xpath=//div[2]@class | central-featured |
assertAttribute | css=input + select@name | anguage |
verifyAttribute | css=input + input@id | searchInput |
- 2nd "verifyAttribute" command will locate the 'input' node using CSS path and look into it for attribute = 'id' containing 'searchInput' text. It will pass.
- 3rd "assertAttribute" will check same thing and will be pass.
- 4th "verifyAttribute" command will locate 'select' node and verify for 'name' = 'language'
- Same way, 5th command "verifyAttribute" will locate element using xpath and verify 'div[2]' node for 'class' = 'central-featured'
- 6th command "verifyAttribute" will be fail and return expected "[error] Actual value 'search' did not match 'search1'". [Note : Here selenium will not stop its execution because of "verify" command]
- 8th command "assertAttribute" will return expected "[error] Actual value 'language' did not match 'anguage'" in log. [Note : Here selenium will stop its execution because of "assert" command so next command "verifyAttribute" will be not executed].
In above example, you clearly understand how to use and difference between assert command "assertAttribute" and verify command "verifyAttribute" in selenium software testing tool. Post your query as a comment bellow this post.
Nice explanation..
ReplyDeleteits very useful for new student
ReplyDeleteits very useful to new students
ReplyDeleteReally helpful for beginners.
ReplyDeleteI'm learning to automate an android app and have a specific scenario in which an user have to re-enter password after timing out for 2 mins. I need to enter password in the application anywhere if the screen somes up. Any suggestions to address this issue
ReplyDelete