Friday, September 14, 2012

Selenium Commands


Selenium Commands

Selenium supports many commands; Selenium commands can be divided in two three types:
  1. Actions
  2. Accessors
  3. Assertions
 Actions: Actions are commands that change the state of the application like clicking links or buttons, or typing some text in the given text box.
Actions are available in different types for example:
clickAndWait, clickAt, clickAtAndWait

Accessors: Accessors examine the state of the application and store the results in variables, e.g. “storeTitle”.

Assertions are like Accessors, but they verify that the state of the application and conforms what is expected.All Selenium Assertions can be used in 3 ways: "assert", "verify", and "waitFor". For example, you can "assertText", "verifyText" and "waitForText". When an "assert" fails, the test is aborted. When a "verify" fails, the test will continue execution, logging the failure. “waitFor" commands wait for some condition to become true. They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting.

    Most common command which I have used in my project is:

Command
Meaning
open
opens a page using a URL
click
performs a click operation on the page.
clickAndWait
performs a click operation on the page, and  waits for a new page to load.
verifyTitle/assertTitle
verifies an expected page title
verifyTextPresent
verifies expected text is somewhere on the page.
verifyTable
verifies a table’s expected contents.
waitForPageToLoad
pauses execution until an expected new page loads.
waitForElementPresent
pauses execution until an expected UI element, as defined by its HTML tag, is present on the page
storetextpresent
Store the text in a variable
storetitlepresent
Store the title in a variable
echo
Print message
select
select an option in a select box by providing the id of the select box and the option value.
pause
Tell the test to pause for a while.  Enter a target of 5000 for 5 seconds
Type
Enter text in a field

While learning about the commands I found a good url which has a complete list of commands as given below for more details please visit this site: http://mishmashmoo.com/

assignId(”Locator”,”String”)
Temporarily sets the “id” attribute of the specified element
capture Screenshot (”File name”)
Captures a PNG screenshot to thespecified file.
Check(”Locator”)
Check a toggle-button(checkbox/radio)
click(”Locator”)
Clicks on a link, button, checkboxor radio button.
clickAt(”Locator”,”Coordinate String”)
Clicks on a link, button, checkboxor radio button.
close()
Simulates the user clicking the”close” button in the title bar of a popup window or tab.
doubleClick(”Locator”)
Double clicks on a link, button,checkbox or radio button.
doubleClickAt(”Locator”,”Coordinate String”)
Double clicks on a link, button,checkbox or radio button.
getAlert()
Retrieves the message of aJavaScript alert generated during the previous action, or fail if there were no alerts.
getAllButtons()
Returns the IDs of all buttons onthe page.
getAllFields()
Returns the IDs of all input fieldson the page.
getAllLinks()
Returns the IDs of all links on the page.
getAllWindowIds()
Returns the IDs of all windows that the browser knows about.
getAllWindowNames()
Returns the names of all windows that the browser knows about.
getAllWindowTitles()
Returns the titles of all windows that the browser knows about.
getAttribute(”Attribute Locator”)
Gets the value of an element attribute.
getBodyText()
Gets the entire text of the page.
getConfirmation()
Retrieves the message of a JavaScript confirmation dialog generated during the previous action.
getCookie()
Return all cookies of the current page under test.
getElementHeight(”Locator”)
Retrieves the height of an element
getElementPositionLeft(”Locator”)
Retrieves the horizontal position of an element
getElementPositionTop(”Locator”)
Retrieves the vertical position of an element
getElementWidth(”Locator”)
Retrieves the width of an element
getEval(”JS Expression”)
Gets the result of evaluating the specified JavaScript snippet.
getLocation()
Gets the absolute URL of the current page.
getMouseSpeed()
Returns the number of pixels between “mousemove” events during dragAndDrop commands (default=10).
getPrompt()
Retrieves the message of a JavaScript question prompt dialog generated during the previous action.
getSelectedId(”Select Locator”)
Gets option element ID for selected option in the specified select element.
getSelectedIds(”Select Locator”)
Gets all option element IDs for selected options in the specified select or multi-select element.
getSelectedIndex(”Select Locator”)
Gets option index (option number, starting at 0) for selected option in the specified select element.
getSelectedIndexes(”Select Locator”)
Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
getSelectedLable(”Select Locator”)
Gets option label (visible text) for selected option in the specified select element.
getSelectedLables(”Select Locator”)
Gets all option labels (visible text) for selected options in the specified select or multi-select element.
getSelectedValue(”Select Locator”)
Gets option value (value attribute) for selected option in the specified select element.
getSelectedValues(”Select Locator”)
Gets all option values (value attributes) for selected options in the specified select or multi-select element.
getSelectOptions(”Select Locator”)
Gets all option labels in the specified select drop-down.
getSpeed()
Get execution speed (i.e., get the millisecond length of the delay following each selenium operation).
getTable(”Table Cell Address”)
Gets the text from a cell of a table.
getText(”Locator”)
Gets the text of an element.
getTitle()
Gets the title of the current page.
getValue(”Locator”)
Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
get Whether This Frame MatchFrameExpression(”Current Frame”,”Target”)
Determine whether current/locator identify the frame containing this running code
get Whether This Window MatchWindowExpression(”CurrentWindow”,”Target”)
Determine whether currentWindow String plus target identify the window containing this running code.
goBack()
Simulates the user clicking the “back” button on their browser.
highlight(”Locator”)
Briefly changes the backgroundColor of the specified element yellow.
isAlertPresent()
Has an alert occurred?
isChecked(”Locator”)
Gets whether a toggle-button (checkbox/radio) is checked.
isConfirmationPresent()
Has confirm() been called?
isEditable(”Locator”)
Determines whether the specified input element is editable, ie hasn’t been disabled.
isElementPresent(”Locator”)
Verifies that the specified element is somewhere on the page.
isPromptPresent()
Has a prompt occurred?
isSomethingSelected(”Locator”)
Determines whether some option in a drop-down menu is selected.
isTextPresent(”Pattern”)
Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
isVisible(”Locator”)
Determines if the specified element is visible.
open(”URL”)
Opens an URL in the test frame.
openWindow(”URL”,”WindowID”)
Opens a popup window (if a window with that ID isn’t already open).
refresh()
Simulates the user clicking the “Refresh” button on their browser.
removeAllSelections(”Locator”)
Unselects all of the selected options in a multi-select element.
removeSelection(”Locator”,”Option Locator”)
Remove a selection from the set of selected options in a multi-select element using an option locator.
select(”Select Locator”,”Option Locator”)
Select an option from a drop-down using an option locator.
selectFrame(”Locator”)
Selects a frame within the current window.
selectWindow(”WindowID”)
Selects a popup window; once a popup window has been selected, all commands go to that window.
setSpeed(”Value”)
Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation).
setTimeout(”Time”)
Specifies the amount of time that Selenium will wait for actions to complete.
start()
Launches the browser with a new Selenium session
stop()
Ends the test session, killing the browser
submit(”Form Locator”)
Submit the specified form.
type(”Locator”,”Value”)
Sets the value of an input field, as though you typed it in.
unCheck(”Locator”)
Uncheck a toggle-button (checkbox/radio)
waitForCondition(”JavaScript”,”Timeout”)
Runs the specified JavaScript snippet repeatedly until it evaluates to “true”.
waitForFrameToLoad(”Frame Address”,”Timeout”)
Waits for a new frame to load.
waitForPageToLoad(”Timeout”)
Waits for a new page to load.
waitForPopUp(”WindowID”,”Timeout”)
Waits for a popup window to appear and load up.
windowFocus()
Gives focus to the currently selected window
windowMaximize()
Resize currently selected window to take up the entire screen




3 comments:

  1. Eagerly waiting post it sooon.............atleast tell the release date?

    ReplyDelete
  2. Finally you posted, great work. Very usefull information to a beginner spend some more time and keep posting with different areas of testing

    Thanks for sharing

    ReplyDelete
    Replies
    1. Glad to know that you found it useful. Yes will be covering different areas also of testing. Thanks for visiting the blog.

      Delete