Selenium IDE Script
Improvement
This Selenium section, you
look at the commands that will create your automation script more complete and
intelligent.
Confirm the Element Presence
You can utilize the given
below commands to confirm the element presence:
- verifyElementPresent – It will returns TRUE if the specified elements were FOUND on the page; and in case of otherwise FALSE
- verifyElementNotPresent – It will returns the TRUE if the particular element was NOT FOUND anywhere on pages; and FALSE in case of present.
The testing script given below
confirms that the User Name textbox is available within the homepage of Mercury
Tours during the text box of First Name is not. The text box of First Name is
actually an element available in the Mercury Tours Registration page, not on
the home page. Strong > Verification of a Certain Text Presence.
Selenium IDE Script Improvement |
Verify Presence of Certain Text
- verifyTextPresent – It will also returns TRUE if the particular text string was FOUND anywhere on the page; otherwise FALSE
- verifyTextNotPresent – IT will returns TRUE if the specific text string was NOT FOUND somewhere on the page; in case of found then FALSE
Point to be Remember that such commands are case sensitive.
For Example: "Atlanta to Las Vegas" will
treat another way from "atlanta to Las Vegas" because of
case sensitiveness. When the verifyTextPresent commands were used on each of
them, the another one passed and the that failed.
Confirmation of Specific Position of any Element
Selenium IDE point to the
position of an element by measuring (in pixels) how distant it’s from the left
or top edges of the window of browsers.
- verifyElementPositionLeft – Confirms if the specified numbers of pixels matched the element distance from the side edges of the page. This will definitely return FALSE if the specified value doesn’t match the distance from the left edge.
- verifyElementPositionTop – Confirms if the particular number of pixels match the element distance from top edge of page. This will return FALSE if the specified value doesn’t match with the distance from the top edge.
Wait commands
andWait commands
Following are the
commands that will wait for the new pages to load before jumping onto the further
commands.
Examples are given below:
- clickAndWait
- typeAndWait
- selectAndWait
waitFor commands
Following are the
commands that wait for the particular conditions to suit true before proceeding
to the further commands (ir-respective of loading of a new pages). Such
commands are more suitable to be utilized on AJAX - based dynamic website that alters the
elements and values without reloading the complete pages.
- waitForTitle
- waitForTextPresent
- waitForAlert
We can
also utilize the combination of "waitForTextPresent" and
"click" to confirm the attendance of any text like ‘Providing your
birthday’.
We can not
utilize the clickAndWait because non
pages were loaded upon clicking on the ‘Why do I need to provide my birthday?’
link. If we do, then testing will get fail
Storing the Variables and the Echo commands
Store
To save the variables for
Selenium IDE, we utilize the command "store".
For
variable access, simply enclose it in the symbol ${ … }. For an example, to input
the values of "myVariable" onto the "userName" textbox of
Mercury Tours, enter ${myVariable} in field of Value.
StoreElementPresent
Such commands store
either "false" or "true" depending on the specified element
presence. The script saves the Boolean value "false" to
"var2" and "true" to "var1". To Confirm, we can
utilize the "echo" commands to show the values of var2 and var1. The
Base main URL can set to homepage of Mercury Tours.
StoreText
Such commands are utilized to save the inner text
of any element onto the variables.
Alerts, Multiple Windows and Pop-up
Alerts are probably the easiest
form of the windows of pop-up. The mostly common Selenium IDE command utilized
in handling the alerts are as given below:
assertAlert
assertNotAlert
|
recovers the communication of the
alerts and assert it to string values that we specified
|
assertAlertPresent
assertAlertNotPresent
|
asserts if any Alert is available
or not
|
storeAlert
|
recovers the alert
messages and saves it in the variables that we will specify
|
storeAlertPresent
|
returns TRUE if any
alert is available; otherwise FALSE
|
verifyAlert
verifyNotAlert
|
recovers the messages of the alerts
and confirms if it is equals to the string values that we specified
|
verifyAlertPresent
verifyAlertNotPresent
|
confirms if any
Alert is available or not
|
Remember following
two things when experiencing with alerts:
- Selenium IDE will click on the button OK automatically from the window of alert and so we will not be capable to check the real alert.
- Selenium IDE will not be capable to grip the alerts that are within the page's onload() functions. It will only be capable to grip alerts that are created after the pages have loaded completely.
Following example, you
will utilize the storeAlert commands to display that even though Selenium IDE
didn’t display the actual alerts, it was still capable to access its messages.
Step 1. Under Selenium IDE, set Base URL to jsbin.com.
Step 2. Develop the script
Step
3. Run the script and don’t guess
that we will be capable to see the actual alert.
Confirmations
Confirmation is pop - ups
that provide you the button for an OK and a CANCEL, as opposed to alerts which provide
us only the OK button. The command we can utilize in handling the confirmations
are similar to those in handling alert.
- assertConfirmation /assertNotConfirmation
- assertConfirmationPresent /assertConfirmationNotPresent
- storeConfirmation
- storeConfirmation Present
- verifyConfirmation /verifyNotConfirmation
- verifyConfirmationPresent /verifyConfirmationNotPresent
However, these are
the extra command that we required to utiliize to instruct Selenium which
option to select, whether the OK or the CANCEL buttons.
- chooseOkOnNextConfirmation /chooseOkOnNextConfirmationAndWait
- chooseCancelOn NextConfirmation
We should utilize
these command before the commands that triggers the confirmation box so that
Selenium IDE will know before hand which option to select. Again, we will not be able to see the actual confirmation
box during execution of script.
Let us test the web page
that has any button that was coded to display whether the user had clicked the
OK or the CANCEL button.
Step 1. Under the Selenium IDE, select the Base URL to jsbin.com
Step 2. Develop the script. This time, OK button will be clicked
first.
Step
3. Run the script and notified that we
don’t see the real confirmation, but the website page was able to point to
which button Selenium IDE had clicked.
Step
4. First Replace the "chooseOkOnNext Confirmation"
command with "chooseCancelOn NextConfirmation"
and run again the script.
Multiple Windows
If we occur to click on the
link that launches the separated window, we must first teach Selenium
IDE to choose that window first before we could access the element within it.
To do all this, we will utilize the title of window as its locators.
We utilze the
selectWindow commands in the switching between the windows.
We will utilize the link jsbin.com/ocinaj/1
whose title is "First Window". The "here" hyperlink found
in that pages will brose Facebook in the new windows, after which we shall teach
Selenium IDE to do all given below:
- From the parent window, the Transfer control to the newly launched Facebook window utilizing the "selectWindow" commands and its title as the locators.
- Confirm the title of the newly window
- Select back the original window utilizing "selectWindow" commands and "null" as its target.
- Confirm the title of the presently chosen window
Step 1. Set the Base URL to jsbin.com.
Step 2. Develop the script as displayed below.
We require the
"pause" commands to wait for the new launched window to load before
we could retrieve its titles.
Step 3. Run the scripts. Notice test case passed, meaning that we
were capable to switch between the windows and confirm their title.
Following point keep in mind always that setting target of selectWindow to "null" will automatically choose the parent window (in such case, the windows where the elements "link = here" is found)
Summary
- The three most commonly utilized the commands in confirming the pages elements are:
- verifyElementPresent/verify ElementNotPresent
- verifyTextPresent/verify TextNotPresent
- verifyElementPositionLeft/verify ElementPositionTop
- Wait commands categorised into below two:
- andWaitcommands – utilized when the page is expected to be loaded
- waitForcommands – utilized when no newly pages are expected to be loaded
- The "save" commands (and all its alternatives) are utilized to save the inconsistent in Selenium IDE
- The "echo" commands are utilized to print the string value or the any variables
- Variables will be enclosed with the ${…} when being printed or utilized on the element.
- Selenium IDE automatically press the OK button when alerts handling.
- During handling the confirmation dialougs, we can instructs Selenium IDE which options to utilize:
- chooseOkOnNextConfirmation /chooseOkOnNextConfirmationAndWait
- chooseCancelOn NextConfirmation
- Window title is utilized as locator when switching between browsers window.
- When utilizing the "selectWindow" commands, set the Target to "null" will automatically direct Selenium IDE to choose the parent windows.
No comments:
Post a Comment