SonnetTEST Framework Commands - sonnettest/TestAutomation GitHub Wiki

The following methods are built to handle page synchronization along with required functionalities. Framework waits for certain time (as in configuration - element_wait) to find an element before it throws time out exception. Similarly Framework ensures that element is visible before performing an action.

In case of ajax call where object get refreshed, user can set optional parameters [setting to 'true'] to wait for following element to be available.

findElement(By locator)

Used to identify a webelement based on the locator parameterized and allow to perform action by invoking click(), sendKey() method.

In case of any expection (like element NOT found), framework writes the details to the error log and abort the test. Test will be considered as fail.

Example

findElement(By.xpath("//*[@href='/moc']")).click();

findElement(By.name("USERNAME")).sendKeys("guest");

findElements(By locator)

Used to build collection of elements based on the locator parameterized. It will used where elements will have same attribute details and select based on the location within the collection / certain criteria. The below example explains selecting a color in the combobox / dropdown. Name of the color is read from test data file (maintained in a datasource object - 'productData')

findElements(By.xpath("//li[@class='select_colour']//ul/li//a")) .selectWebElement(Attributes.TITLE, productData.GetData("style")).click();

executeJavaScript(String command)

Used to directly perform action on the web element. User needs to pass valid javascript command to perform action. executeJavaScript("$('#chkOneWay').click();");

waitForJQuery2Process()

Used for ajax calls wherein framework wait for JQuery get processed

waitForJavaScript(String javaScript)

Used for wait for executing javascript command.

getTitle()

Return title of the browser.

getCurrentUrl()

Return current URL

getPageSource()

Return current page source

switchToWindow(int index)

Switch to window based on the location passed as parameter

switchToFrame(String nameOrId) {

Switch to Framework based on name or id given to the frame

switchToFrame(WebElement frameElement)

Select a frame using its previously located web element

switchToFrame(int index)

Select a frame based index (zero-based).

jsSwitchToFrame(int Index)

Select a frame based index (zero-based) using Java script.

switchToParentFrame()

Set focused to parent frame

switchToDefault()

Selects either the first frame or the main page that contains iframes.

alertAccept()

Accept button is clicked on Alert window, if present

alertDismiss()

Dismiss button is clicked on Alert window, if present

alertGetText()

Returns text present on Alert window, if present

isAlertPresent()

Check whether Alert window is present on the browser

keyBoard()

Perform keyboard operation

alertSendKeys(String inputValue)

Enter value on the Alert window, if present


The following methods are called following findElement(), findElements(). The method gets invoked once an element is available to perform following action.

sendKeys(String inputValue, Boolan waitRefresh)

Enter data 'inputValue' into editable text box.

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

submit()

It is equivalent to pressing {ENTER} to submit the page.

waitForElement()

Wait for current element to be visible before performing any action like click(), sendKeys();

waitForElements()

Wait for element to be visible.

waitForElementRefresh()

Wait for element to refresh post ajax call

waitForElementToDisplay()

Wait for element to visible on the browser

click(Boolean waitType)

Click on the element identified - like checkbox, button, text box etc

User can set two parameters, which are optional. First parameter is to wait for object refresh (setting to 'true' to wait for completing ajax call).

Second parameter is to wait for page refresh (setting to 'true')

clear()

Clear the value in the element identified.

deselectByVisibleText(String visibleText, Boolean waitRefresh)

Remove selection of text in the dropdown / combo box

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

selectByVisibleText(String visibleText, Boolean waitRefresh)

To Select all options that display text matching the given argument. It will not look for any index or value, it will try to match the VisibleText (which will display in dropdown)

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

selectByValue(String selectValue, Boolean waitRefresh)

Select the options that have a value matching with the given argument by the user

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

Example: <select name="Mobiles"><option selectd> Please select</option>

<option value="iphone">iPhone</option>

<option value="nokia">Nokia</option>

<option value="samsung">Samsung</option>

<option value="htc">HTC</option>

<option value="blackberry">BlackBerry</option>

</select>

deselectByValue(String selectValue, Boolean waitRefresh)

Remove selected value in the drop down

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

selectByIndex(int selectIndex, Boolean waitRefresh)

To Select the option based on the index given by the user. There is an attribute called "values" which will have the index values.

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

selectByOption(String selectValue, Boolean waitRefresh)

It is an alternative option to method 'selectByVisibleText(String visibleText)'

Second parameter is optional. In case of Ajax call, user can set to true to wait for element refresh.

isEmpty()

Returns TRUE if the selected element is empty. Else it returns FALSE

isSelected()

Returns TRUE if the selected element is checked [applicable only for checkbox]. Else it returns FALSE

isDisplayed()

Returns TRUE if the element is visible on the browser. Else it returns FALSE.

isEnabled()

Returns TRUE if the element is editable. Else it returns FALSE.

getAttribute(Attributes attribute_type)

Return value in the specified attribute of the selected element (selected using findElement() method).

selectWebElement(Attributes attribute_type, String expectedValue)

It is alternative to methods like selectByValue() and selectByVisibleText(). It should be called following findElements() method to select a value / element within the collection.

selectWebElement(int elementIndex)

It is alternative to methods like selectByIndex(). It should be called following findElements() method to select a value / element within the collection using index.

verify(AssertType assert_type, String... expectedValue)

Used to assert / verify a selected / identified web element. Expected Value can have two values (as separate parameter) to verify against value in the element and message to be displayed in case verification is successful.

In case assertion fails, expected and actual values will be written to test result.

moveToElement()

Move to the element currently identified

⚠️ **GitHub.com Fallback** ⚠️