Monday, 5 October 2015

Selenium IDE Commands

Different between "verifyText" and "assertText" in selenium

Here let me describe you main difference between assert and verify in selenium IDE and selenium RC. assert and verify commands are useful for verifying condition match or not.
Verify command will verify the condition and if its not match, it will give error message in Log area and will start executing next commands. while in assert command, if condition does not match then it will stop remaining script execution.

In bellow example, you can understand difference better.
New Test
Command Target Value
open https://www.google.co.in/
verifyText css=#gb_2 > span.gbts xyz
assertText css=#gb_2 > span.gbts xyz
verifyText css=#gb_2 > span.gbts Images

Here element "css=#gb_2 > span.gbts" contains text "Images"

In this example, first "verifyText" command will go for checking that element "css=#gb_2 > span.gbts" contains text "xyz"? it
will return false because element "css=#gb_2 > span.gbts" has "Images" text but it will not stop next script execution. It will execute next command "assertText". Here is the same condition so that it will return false and due to the assert command, it will not execute next command.
________________________________________________________________________________

"type" and "typeAndWait" command in selenium IDE

"type" command
"type" command is useful for typing keyboard key values into text box. you can also use it for selecting values of combo box.
New Test
Command Target Value
open http://software-testing-tutorials-automation.blogspot.in
type name=email youremailid@mail.com
click css=input[type="submit"]
In this example, First it will type text "youremailid@mail.com" into text field "name=email" and then it will
click on button element "css=input[type="submit"]".
"typeAndWait" command
"typeAndWait" command will be useful when your typing completed, page start reloading. This command will wait for page to reload. If there is not page reload event on typing, then you have to use simple "type" command.

"assertTextPresent" and "assertTextNotPresent" command in selenium IDE 

"assertTextPresent" command

"assertTextPresent" command is useful for verifying and asserting selenium if given text is not present on page. It will return false as error if specified text is not present on page and will stop execution.


New Test
Command Target Value
open https://www.google.co.in/
assertTextPresent Maps
verifyTextPresent Maps

In above example, selenium IDE will stop execution if text "Maps" not present on page.



"assertTextNotPresent" command

"assertTextNotPresent" is assertion for if specified text present on page. You can use this command when
you want to stop execution of selenium IDE when some text appears on page.


New Test
Command Target Value
open https://www.google.co.in/
assertTextPresent Maps
assertTextNotPresent Maps
verifyTextPresent Maps

In this example, "assertTextNotPresent" will stop execution if text "Maps" present on page.
___________________________________________________________________________ 

"pause", "refresh" and "waitForPageToLoad" commands in selenium IDE

"pause" Command
"pause" command is simple wait command and useful for stop execution of selenium IDE for given time. In bellow given example, it will wait for 5 second and then it will execute next "refresh" command.
New Test
Command Target Value
open https://www.google.co.in/
pause 5000
refresh

waitForPageToLoad 10000
open https://www.google.co.in/imghp?hl=en&tab=wi
"refresh" Command
 "refresh" command is useful for refreshing page. It will just refresh page and then will start execution of next command. It will not wait for page to reload. So that you need to use "waitForPageToLoad" or any other
element waiting command with "refresh" command. Execute above example for more reference.

"waitForPageToLoad" Command
"waitForPageToLoad" is useful to stop selenium IDE execution until page not get loaded successfully. It wait till given time in target column. Selenium IDE will execute next command once page loaded successfully on given time.
In above example, "waitForPageToLoad" will wait for 10 seconds to page load and then it will execute next "open" command. If page loading will take time < 10 seconds then it will start next command execution as soon as page loaded successfully. 10 second is maximum time to wait.
______________________________________________________________________________

"storeLocation" and "storeTitle" commands in selenium IDE

"storeLocation" Command

"storeLocation" command is useful to store current selected window's URL. See bellow given example for more reference.

New Test
Command Target Value
open https://www.google.co.in
storeLocation i
echo ${i}
In this example, My current window's URL will be stored into variable "i" and now i can use that variable
value anywhere in my script.


"storeTitle" Command

"storeTitle" command is storing title of current selected window. see bellow given example for more reference. It will store current selected windows title in to variable "j".
New Test
Command Target Value
open https://www.google.co.in
storeTitle j
echo ${j}
 ______________________________________________________________________________

Use of "select" and "selectAndWait" command in selenium IDE

"select" Command
Purpose of "select" command is to select label from drop down/combo box or list box.
New Test
Command Target Value
open http://only-testing-blog.blogspot.in/2014/01/textbox.html
select name=FromLB Russia

In this example, You need to add combo box id/Name/Xpath into target column and need to add option's value or visible text or index into value column. Supposing if your option name is "Russia" then you need to add it as Russia.

Here you can use four types of optionLocators. You can use labelPattern, valuePattern, id of label or index of label in value field.
"selectAndWait" command
Here something different then the "select" Command. If your page is reloading when you select label from drop down then you need to use "selectAndWait" command. It will select the specified label and then it will wait for page to load successfully.
______________________________________________________________________________

"storeAllButtons", "storeAllFields" and "storeAllLinks" command in selenium IDE

All these three commands useful only some time when you have multiple buttons or multiple fields or multiple links on page and you need ids of every element. Let me describe all these commands with example for better understanding.
"storeAllButtons" Command
If you are working on any webpage and you need ids of all available buttons on page then you can use storeAllButtons command. This command will store all buttons ids in given variable.

New Test
Command Target Value
open https://www.google.com
storeAllButtons i
echo ${i}
storeAllFields j
echo ${j}
storeAllLinks k
echo ${k}
In this example, storeAllButtons will store ids of all available buttons on google home page in variable "i". If
any button has not any id then it will return null.

"storeAllFields" Command
Same as storeAllButtons command, "storeAllFields" Command will store ids of all input fields of page in given variable "j" as shown in above example. Same way, if any field has not id, it will return null.
"storeAllLinks" Command
 storeAllLinks command used for storing ids of all available links on page. In above example, it will store into variable "k"
___________________________________________________________________________________

"check", "uncheck", "checkAndWait" and "uncheckAndWait" command example of selenium IDE

You can use check and uncheck commands only with checkbox and radio buttons of webpage. Let we see how we can use check command in selenium IDE.

"check" command

check command will check the check box if have check box on your webpage. You can also select radio button using check command.

New Test
CommandTargetValue
openmail.google.com/
checkid=PersistentCookie
uncheckid=PersistentCookie

In above example, check command will check the check box with id=PersistentCookie. You can use id of radio button if you have radio button on page. You can also use "click" command at place of "check" and
"uncheck" commands with check box or radio buttons.


"uncheck" command

As shown in above example, "uncheck" command will uncheck the check box if it is checked. In same way it will deselect radio button if it is selected.

"checkAndWait" and "uncheckAndWait" commands

You can use wait command with check and uncheck command when your webpage reloads after checking or unchecking check box or radio button. 

__________________________________________________________________________________

Use of "mouseOver", "mouseOut", "mouseOverAndWait" and "mouseOutAndWait" commands in selenium IDE 

You can use mouseOver and mouseOut command when your targeted element has effect on mouse over and mouse out. Targeted element can be button or image or link or anything else. 
Suppose you have one image on web page and it is changing image when you move mouse on it. Now if you want to see this effect with selenium IDE then you can use "mouseOver" and "mouseOut" Commands. Let we see it with example.
"mouseOver" Command
On Google search page, there is one button named "Google search". That button's text becomes dark when we put mouse cursor on button and it becomes light when we remove mouse cursor from button. Let we check it with selenium IDE.
New Test
CommandTargetValue
openhttps://www.google.com
mouseOverid=gbqfba
pause5000
mouseOutid=gbqfba
In this example "mouseOver" command will put mouse cursor on button id=gbqfba virtually. You can see its
effect on button. Button's text will remain darker for 5 seconds because i have used "pause" 5 second command after "mouseOver" command.
"mouseOut" Command
In above example, mouseOut command will remove mouse cursor from button "Google search" after 5 seconds.

"mouseOverAndWait" and "mouseOutAndWait" Command
You need to use "mouseOverAndWait" and "mouseOutAndWait" commands when you move in or move out mouse cursor from target element and page get reloaded. Other function is same as mouseOver and mouseOut command.
 _______________________________________________________________________________

Use of "storeSelectedIndex" and "storeSelectedIndexes" command in selenium IDE 

"storeSelectedIndex" Command

storeSelectedIndex works with only select or multi-select target element like drop down and list box. Using this command, you can get option index of selected option.


New Test
CommandTargetValue
storeSelectedIndexctrl5_Main_ddlStateindexno
echo${indexno}
storeSelectedIndexesctrl5_Main_ddlStateindexnos
echo${indexnos}



In above example, ctrl5_Main_ddlState target element is list box.Here command "storeSelectedIndex" will store index value of current selected option of target element ctrl5_Main_ddlState list box into variable "indexno". We can also use this command with any drop down. We can use "storeSelectedIndex " if there is
selected only one option from list box. If there are multi selected option into target element then we have to use storeSelectedIndexes command

"storeSelectedIndexes" Command
Same as "storeSelectedIndex" command, "storeSelectedIndexes" command will be used with drop down or list box to get index value of multiple selected options. In above example, "storeSelectedIndexes" command will store index of all selected options of element "ctrl5_Main_ddlState" into variable "indexnos". we can use "echo" for seeing stored values into given variable.
____________________________________________________________________________

"assignId" and "captureEntirePageScreenshot" commands of selenium IDE 

"captureEntirePageScreenshot" command


This command is very useful for capture and save full page screenshot. You can use this command anywhere in between. It will store screen shot of current selected browser tab.

New Test
Command Target Value
open http://www.google.com
captureEntirePageScreenshot D:\\selenium.jpg
In above example, "captureEntirePageScreenshot" command will capture and store screenshot of Google home page in "D" drive with file name selenium.jpg. You can change file name and file storing path as you
wish. Main benefit of this command is it will store whole entire page screen shot without considering length of the page.
"assignId" command
 "assignId"  command is useful to assign temporary "id" to an element. Main benefit of this command is you can assign id to an element rather than a slow/complicated XPath. Once you will assign id to an element, you can use that id as an element identifier. Don't forget that id will disappear once your page will be reloaded.

New Test
Command Target Value
open http://www.google.com
assignId id=gbqfq box
assignId id=gbqfb button
type box Download Selenium
click button

In above example, i have assigned id "box" to Google search box and assigned id "button" to Google search button. In next command, i have used that id for Google search box and button.
____________________________________________________________________________

"assertEditable" and "assertNotEditable" command in selenium IDE 

"assertEditable"  Command
You can use "assertEditable" command with only and only input fields like text box, list box, drop downs etc. You can check and assert that targeted element is editable or not. If targeted element is not editable then it will stop execution of remaining selenium script.


New Test
CommandTargetValue
openhttps://www.google.com
assertEditableid=gbqfq
assertNotEditableid=gbqfq
assertEditableid=gbqfq

Here in this example, second command(assertEditable) will check that target element search text box(id=gbqfq)is editable or not. If its editable then and then it will execute next command. If it is not editable
then it will stop execution of next all commands.

"assertNotEditable" Command
Same as "assertEditable"  Command, "assertNotEditable" command will fail to execute if specified element is not editable. Here it will check opposite condition compared to "assertNotEditable" command.
Third command(assertNotEditable) will check that is search text box(id=gbqfq)is editable or not. It will stop execution if it is editable.
___________________________________________________________________________________

"storeSelectedLabel" and "storeSelectedLabels" 

"storeSelectedLabel" Command
We can use "storeSelectedLabel" Command only with drop down and list box. When you want to know or you need to compare selected option value of drop down with some other value at that time first you need to store value of selected label. In such condition you can use "storeSelectedLabel" Command. Let we see with example.

New Test
Command Target Value
storeSelectedLabel ctrl55_Contentitem_State value
storeSelectedLabels ctrl55_Contentitem_Statevalues


In above example, First command "storeSelectedLabel" will store selected label name of drop down(ctrl55_Contentitem_State) into variable "value". Here "ctrl55_Contentitem_State" is the name of drop
down. You need to replace it with your drop down id or name or xpath. Here keep in mind one thing, You can use "storeSelectedLabel" only with single selected label. If you have list box and multiple options selection then you have to use "storeSelectedLabels" command to store all selected label names. See bellow description for more info.

"storeSelectedLabels" Command
"storeSelectedLabels" Command will be used with multiple selected options. It will store all selected labels name. In above example, second command "storeSelectedLabels" will store all selected labels name of drop down(ctrl55_Contentitem_State) into variable "values".
_____________________________________________________________________________

"storeSelectOptions" and "storeValue" commands in selenium IDE

"storeSelectOptions" Command
We can use "storeSelectOptions" command with only list box and drop downs. Function of this command is it will store all option labels names of targeted drop down or targeted list box in to variable. See bellow given example.

New Test
Command Target Value
storeSelectOptions ctrl55_Contentitem_State label
storeValue chk_box_01value

In above example, "storeSelectOptions" command will store all option labels names of targeted list box
(ctrl55_Contentitem_State) in to variable "label". You can use this command when you need all labels names of drop down.

 "storeValue" Command
We can use "storeValue" command with radio button or check box. It will check and store targeted element's value "ON" or "OFF". "ON" means selected and "OFF" means not selected.
In above example, It will check specified target element chk_box_01's value. If its checked then it will store "ON" into variable "value" else it will check "OFF" in variable "value". In this way you can check and store current state of specified targeted radio button or text box.
___________________________________________________________________________________

Use of "break" and "goBack" Commands in selenium IDE

"break" Command
Main use of "break" command is to halt execution of script until user resume it again manually. Supposing if you want to take some actions manually at any specific stage of your currently running script, then you need to halt your current execution and you can do it with "break" command. See bellow example for better understanding.

New Test
CommandTargetValue
openhttps://www.google.com
break

openhttps://www.yahoo.com
goBack



Here first it will open "https://www.google.com" URL in browser. Second command will halt selenium IDE execution and now it will show "Pause/Resume" button enabled in selenium IDE window. Your script's execution will remain halted until you manually resume it by pressing "Pause/Resume" button on selenium IDE
window. During halt period, you can take any action on you browser. Here keep in mind one thing - you have to resume script execution manually it will not resume automatically.

"goBack" Command
"goBack" command same like you press "back" button on your browser. In above example, forth command will virtually click "back" button of your browser on "https://www.yahoo.com" to open previous page "https://www.google.com".

"addSelection" and "removeSelection" command example in selenium IDE

"addSelection" Command

In multiselect list box, when you need to select multiple values from list box, "addSelection" command will be helpful in selenium IDE. "Select" command will select only single value from list box but "addSelection" command will add new value selection in list box means previously selected values will remain selected as it is and will add new selection.
Run bellow given example yourself to understand it better. In this example, first i am adding value "Japan" from list box using "addSelection" command and next 3 commands will select 3 new values using "addSelection" command.

New Test
CommandTargetValue
openhttp://only-testing-blog.blogspot.in/2013/09/testing.html
addSelectionname=FromLBlabel=Japan
addSelectionname=FromLBlabel=Mexico
addSelectionname=FromLBlabel=India
addSelectionname=FromLBlabel=Spain


"removeSelection" Command

"removeSelection" command works in opposite of "addSelection" command. It will remove selection of
specified value from multiselect list box.
In bellow given example, "removeSelection" command will remove selection of label "India" from list box.
New Test
CommandTargetValue
openhttp://only-testing-blog.blogspot.in/2013/09/testing.html
addSelectionname=FromLBlabel=Japan
addSelectionname=FromLBlabel=Mexico
addSelectionname=FromLBlabel=India
addSelectionname=FromLBlabel=Spain
removeSelectionname=FromLBlabel=India
 ________________________________________________________________________________

Use of "addSelectionAndWait" and "removeSelectionAndWait" command

 "addSelectionAndWait" command in selenium IDE
When you are adding selection into multi select list box and page reloading due to the adding selection, you need to use addSelectionAndWait command to handle page loading event. You can use addSelection if page not reloading after adding selection.
I have not any perfect example of page reloading when adding selection in list box. Let me try to show you how to use addSelectionAndWait command.


New Test
CommandTargetValue
openhttp://only-testing-blog.blogspot.in/2013/09/testing.html
addSelectionname=FromLBlabel=Japan
addSelectionname=FromLBlabel=India
addSelectionAndWait name=FromLBlabel=Mexico

In this example, when selection label=Mexico, page not reloading so that this command will be not helpful
here. but you just need to consider it as page reloading.
 "removeSelectionAndWait" command in selenium IDE
Same as described in above example, removeSelectionAndWait command will works when page reloading when removing selection from multi select list box. here is example of how to use "removeSelectionAndWait" command in selenium IDE so that you can get some idea.
New Test
CommandTargetValue
openhttp://only-testing-blog.blogspot.in/2013/09/testing.html
addSelectionname=FromLBlabel=Japan
addSelectionname=FromLBlabel=Mexico
addSelectionname=FromLBlabel=Italy
addSelectionname=FromLBlabel=Greece
removeSelectionAndWai name=FromLBlabel=Mexico
________________________________________________________________________________________

Use of "altKeyDown" and "altKeyUp" in selenium with example

"altKeyDown" command
"altKeyDown" command works just like you are pressing alt key of your keyboard. It will keep pressed alt key until "altKeyUp" not executed. You can use this command when you need to perform any action by pressing alt key.
Let me show you use of "altKeyDown" command with example. In bellow given example, altKeyDown command will press and hold alt key down then click command will click on targeted element.

New Test
CommandTargetValue
openhttps://www.google.co.in/
altKeyDown

clickcss=#gb_2 > span.gbts
altKeyUp


"altKeyUp" command
"altKeyUp" will release the pressed alt key. In above example, altKeyUp command will release pressed alt key using altKeyDown command. 
 
________________________________________________________________________________

Using "answerOnNextPrompt" and "assertPrompt" commands in selenium

"answerOnNextPrompt" command
Sometime if you seen , there is display text box with popup message to write some thing in message box. In such popup "answerOnNextPrompt" command is useful to providing answer in popup message. "answerOnNextPrompt" command will type the message whatever you want to type in popup.
Here is one perfect example of "answerOnNextPrompt" command to learn it better. In bellow given example, when user clicking on "Try it" button, It is opening one popup message box with text box. answerOnNextPrompt command will type text "Test" into popup message text box. Please note one thing here - answerOnNextPrompt command is written before click button command which opens the popup. In this way we can predefine the answer what we want to enter into popup text box.

New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt
selectFrameview
answerOnNextPromptTest
click css=button
assertPrompt Please enter your name

"assertPrompt" Command

"assertPrompt" useful to retrieving the message of the most recent JavaScript question prompt. In above example, it is retrieving the message "Please enter your name" from prompt dialog generated during the previous action 
 
_______________________________________________________________________________

Difference between "verifyAlert" and "assertAlert" command in selenium

There are too many commands starting with "verify" and "assert" text. Both these commands are same excluding one difference and that difference is after execution of "verify" command if condition is match or not match selenium will execute next commands but in case of execution of "assert" command if condition
returns false then selenium will stop remaining command's execution.
Let me show you that difference with "verifyAlert" and "assertAlert" commands with examples. You can view "assertAlertNotPresent" and "assertAlertPresent" commands example here. Both these commands are also very useful in software testing using selenium IDE.
"verifyAlert" command
"verifyAlert" command will retrieves and verify alert message text and also it will take action on alert box. it will return error message if expected alert not displayed. Let's we see it with example.



New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
selectFrameview
clickcss=input[type="button"]
verifyAlertHello! I am an alert box!1
selectWindownull
assertTitleTryit Editor v1.6

In this example, verifyAlert will verify alert message text with text "Hello! I am an alert box!1". Here it will show error message in log because real text of alert box is "Hello! I am an alert box!". but even after error selenium will execute remaining 2 commands. Here it will not show you error in log if given text "Hello! I am an alert box!" at place of "Hello! I am an alert box!1" with verifyAlert command.
"assertAlert" command
Same as verifyAlert command, "assertAlert" will also verify text and take action on alert box but if alert text not matches then it will stop execution. See bellow given example.

New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
selectFrameview
clickcss=input[type="button"]
assertAlertHello! I am an alert box!1
selectWindownull
assertTitleTryit Editor v1.6

In this example, assertAlert command will show error because alert text "Hello! I am an alert box!1" is not matching with real alert text "Hello! I am an alert box!" and it will not execute remaining 2 commands.
__________________________________________________________________________

selenium command "chooseCancelOnNextConfirmation" and "chooseOkOnNextConfirmation" with example

"chooseCancelOnNextConfirmation" command
"chooseCancelOnNextConfirmation" command used with confirmation popup box. When you are performing some major action like deleting records at that place you can see this kind of confirmation message box to proceed or to cancel the process. "chooseCancelOnNextConfirmation" command will click on cancel button on this kind of action.
Here is the example of "chooseCancelOnNextConfirmation" command.In bellow given example, selenium will click on cancel button of confirmation box. Here it is predefined action to perform on next command.

New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm
selectFrameview
chooseCancelOnNextConfirmation

click css=button
assertConfirmation Press a button!

"chooseOkOnNextConfirmation" command


"chooseOkOnNextConfirmation" command will click on Ok button on next confirmation box. see bellow given example for better understanding

New Test
CommandTargetValue
openhttp://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm
selectFrameview
chooseOkOnNextConfirmation

click css=button
assertConfirmation Press a button!
 
_______________________________________________________________________________

Using "storeElementPositionLeft" and "storeElementPositionTop" Commands in selenium

"storeElementPositionLeft" Command
In selenium, Many times you need  horizontal and verticle position of element on page. When you need any element's horizontal position on the page, you can use "storeElementPositionLeft" Command. It will return and store element's horizontal position in to specified veriable in value column.
In Bellow given example, storeElementPositionLeft command will store google search box's horizontal position in to variable "left".


New Test
CommandTargetValue
openwww.google.com
storeElementPositionLeftgs_htif0left
echo${left}
storeElementPositionTopgs_htif0top
echo${top}

"storeElementPositionTop" Command
"storeElementPositionTop" Command is useful to store vertical position of an element in to variable. In above wxample, storeElementPositionTop command will store google search box's vertical position in to variable "top".
 
__________________________________________________________________________

Handling events like focus or blur in selenium with "fireEvent" command

There are many types of HTML DOM Events available on web page. In selenium IDE, "fireEvent" command is the solution to handle such kind of events. Here i am trying to show you the use of "fireEvent" command with focus or blur event. You can handle any other event in this way.
"fireEvent" command with "focus" event
Let we see it with example. In bellow given example, when element "css=input[type="text"]" gets focus, its color becomes yellow. Here i have used "fireEvent" command to get focus on that element. Run the script and observe yourself. You can use this command combination when the event occurs when an element gets focus. I have placed 5 second pause period to see event's effect.

New Test
CommandTargetValue
openhttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onfocus
selectFrameview
pause5000
fireEventcss=input[type="text"]focus

"fireEvent" command with "blur" event
In bellow given example, when element "id=fname" lost the focus, all characters typed in text box are converted into uppercase. Here is the event occurs when a form element loses focus. So we can use "fireEvent" command with "blur" event to see its effect.

New Test
CommandTargetValue
openhttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onblur
selectFrameview
typeid=fnamea
pause5000focus
fireEventid=fnameblur

__________________________________________________________________________

Use of "setSpeed" and "setTimeout" commands in selenium IDE

"setSpeed" and "setTimeout" are very basic useful commands in selenium. User can controll selenium speed and timeout period when running the script.
"setSpeed" Command
"setSpeed" Command setup the delay between tow command execution or we can say it is useful to managing the execution speed of  selenium. By default there is not any such delay but if your application is slow then you have to use "setSpeed" Command in your sript.
Here is the simple example where i have set up 3000 milisecond speed. First run this script with "setSpeed" Command and then run it by removing "setSpeed" Command to see its difference.

New Test
CommandTargetValue
setSpeed3000
setTimeout50000
openhttp://www.google.com/
clickAndWaitcss=#gb_2 > span.gbts
clickAndWaitcss=#gb_8 > span.gbts
clickAndWaitcss=#gb_78 > span.gbts


"setTimeout" command
"setTimeout" command controlling the timeout period for the action to complete. If your application is too much slow then obviously it will take more time to complete specific request. By default selenium's timeout period is 30000 miliseconds. Now supposing if your application is slow and it is taking more than 30000 miliseconds to complete the request then your script will fail after 30000 miliseconds. To increase this timeout period we can use "setTimeout" command.
In above given example, I have set 50000 milisecong timeout period so that it will wait till 50000 miliseconds to complete specific request.
 
_____________________________________________________________________________

use "storeElementHeight" and "storeElementWidth" to measure element's height and width in selenium

"storeElementHeight" command

"storeElementHeight" command useful to measure the height of elements like button, textbox, images etc. You need to measure element's height and width in pixel to pixel testing. Using selenium, you can measure it very easily. "storeElementHeight" command returns height of targeted element and store it into variable specified in value field.
Here is the one simple example of measuring height of google search box(Text field). In bellow given example, "storeElementHeight" command will store height of search box into variable "i". "echo" helps you to see variable's value (height of an element).

New Test
CommandTargetValue
open
http://www.google.com/

storeElementHeightid=gbqfqi
echo${i}
storeElementWidthid=gbqfqj
echo${j}


"storeElementWidth" command

Same as "storeElementHeight" command, "storeElementWidth" command store element's width in to given variable in value field. In above example, "storeElementWidth" command will store width of search box into variable "j". "echo" helps you to see variable's value(width of an element).

______________________________________________________________________________

Example of "waitForAllFields" and "waitForAllButtons" command in selenium IDE

"waitForAllFields" Command

Sometimes when page speed or internet speed is too much slow and page taking too much time to load its element in that case if your targeted element not appears on page withing timeout period then your script will fail. In such cases you need to use commands like "waitForAllFields" and "waitForAllButtons" in selenium IDE.

There are 3 types of assertions available in selenium IDE
1. assert
2. verify
3. waitfor
"waitForAllFields" command will pause the selenium till the given time in value column if the fields which are specified in target column are not appear on the page. Here field means input fields. In bellow given example,
"waitForAllFields" command will wait for 50000 milliseconds for field "sb_form_q" to appear on page.

New Test
CommandTargetValue
openhttp://www.bing.com/
waitForAllFieldssb_form_q5000
waitForAllButtonssb_form_go5000

"waitForAllButtons" Command
Same as "waitForAllFields" command, "waitForAllButtons" command will wait for the button to appear on page in given time.In above example, "waitForAllButtons" command will wait for 50000 milliseconds for button "sb_form_go" to appear on page.
____________________________________________________________________________
 

Use of "verifyLocation" and "assertLocation" in selenium

"verifyLocation" Command
Soometimes you need to check the URL of current selected window to perform some actions. In such cases, selenium has two commands to verify the absolute URL of the current selected page. "verifyLocation" and "assertLocation".
"verifyLocation" command will just verify your trageted URL with absolute URL of the current page and returns error message if match not found and will go for executing next command. In bellow given example, first "verifyLocation" will becomes pass but 2nd "verifyLocation" will be fail because trageted URL will not
match with the absolute URL of the current page. But it will not stop execution and will go for executing next command.

New Test
CommandTargetValue
openhttps://www.google.co.in/
verifyLocationhttps://www.google.co.in/
verifyLocationhttps://www.yahoo.com
assertLocationhttps://www.yahoo.com
assertLocationhttps://www.google.co.in/

"assertLocation" Command
"assertLocation" Command will check and compare targeted URL with absolute URL of the current selected page and will return error message if both URLs not match. If "assertLocation" Command fails then selenium will stop execution of sript. In above example, 1st "assertLocation" Command will return error message so that next command will be not executed.
 
________________________________________________________________________________

Selenum IDE Example of "assertElementPresent" and "assertElementNotPresent" commands

"assertElementPresent" Command
"assertElementPresent" command is useful to confirm element availability on page after user taking some action or navigate to some other page. It will force selenium to stop execution if targeted element not found on the page. It will continue execution if return result of condition "assertElementPresent" = false and will stop execution if return result of condition "assertElementPresent" = true.
In bellow given example, command "assertElementPresent" will verify that element "id=gbqfba" is there on the page or not. if element "id=gbqfba" (google search button) found on the page then it will execute next
command else it will return true in execution log and stop the execution.

New Test
CommandTargetValue
openhttps://www.google.co.in/
assertElementPresentid=gbqfba
typeid=gbqfqsoftware testing tutorials automation blog
clickid=gbqfb
pause3000
assertElementNotPresentid=gbqfb
typeid=gbqfqdownload selenium ide free

"assertElementNotPresent" command
in the opposite condition, "assertElementNotPresent" command will stop selenium execution if targeted element found on the page. In above example, "assertElementNotPresent" command verifies that element "id=gbqfb" (google search button) is there on the page? If yes then it will stop execution else it will execute next command.
__________________________________________________________________________________
 
 

Working with "verifyTable" and "verifyNotTable" commands with example in selenium IDE

"verifyTable" Command


When you are working with table content with selenium IDE then you must have knowledge of how to use "verifyTable" Command. "verifyTable" Command verifies the text of targeted table's row and column. With "verifyTable" Command, you must have to specify your row and column matrix with target element. Example table.0.1 describes row no 0 and column no 1.

In bellow given example, "verifyTable" Command will verifies that table's row no 0 and column no 1 contains text "Last Name" or not. It will be pass if actual value match with given value in value field else it will return error message in log. In this case it will be pass. You can check it your self by replacing text "Last Name"
with "ABC". It will return error message but as per verify command property, it will not stop execution of remaining commands.

New Test
CommandTargetValue
openhttp://www.w3schools.com/html/html_tables.asp
verifyTablecss=#main > table.0.1Last Name
verifyNotTablecss=#main > table.0.0First Name

"verifyNotTable" command
Here is the opposite behaviour than the "verifyTable" Command. "verifyNotTable" command verifies the text on given table location and if match found then it will return error message. In above given example it will return error message because target table location "css=#main > table.0.0" already contains text = "First Name".
______________________________________________________________________________
 

 



No comments:

Post a Comment