Package com.shaft.cucumber
Class ElementSteps
java.lang.Object
com.shaft.cucumber.ElementSteps
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clicks on a certain element using Selenium WebDriver, or JavaScript.void
clickAndHold
(String locatorType, String locatorValue) Waits for the element to be clickable, and then clicks and holds it.void
clipboardActions
(String action, String locatorType, String locatorValue) Attempts to perform a native clipboard action on the text from a certain web element, like copy/cut/pastevoid
doubleClick
(String locatorType, String locatorValue) Double-clicks on an element using Selenium WebDriver's Actions Libraryvoid
dragAndDrop
(String sourceLocatorType, String sourceLocatorValue, String destinationLocatorType, String destinationLocatorValue) Drags the source element and drops it onto the destination elementvoid
dragAndDropByOffset
(String locatorType, String locatorValue, int xOffset, int yOffset) Drags the source element and drops it onto the determined offsetvoid
Hovers over target element.void
Sends a keypress to the target element.void
Selects an element from a dropdown list using its displayed textvoid
setValueUsingJavaScript
(String value, String locatorType, String locatorValue) Used to SetProperty value for an element (hidden or visible) using javascriptvoid
submitFormUsingJavaScript
(String locatorType, String locatorValue) Used to submit a form using javascriptvoid
Checks if there is any text in an element, clears it, then types the required string into the target element.void
typeAppend
(String text, String locatorType, String locatorValue) Appends the required string into the target element, regardless of the current text value.void
typeFileLocationForUpload
(String absoluteFilePath, String locatorType, String locatorValue) ValidationEnums the required file path into an input[type='file'] button, to successfully upload the target file.void
typeSecure
(String text, String locatorType, String locatorValue) Checks if there is any text in an element, clears it, then types the required string into the target element.void
waitForElementToBeNotPresent
(String locatorType, String locatorValue) Waits dynamically for a specific element to achieve the desired stateOfPresence on the current page.void
waitForElementToBePresent
(String locatorType, String locatorValue) Waits dynamically for a specific element to achieve the desired stateOfPresence on the current page.void
waitForTextToChange
(String locatorType, String locatorValue, String initialValue) Waits dynamically for a specific element's text to change from the initial value to a new unknown value.
-
Constructor Details
-
ElementSteps
-
-
Method Details
-
type
@When("I Type {string} into the element found by {string}: {string}") public void type(String text, String locatorType, String locatorValue) Checks if there is any text in an element, clears it, then types the required string into the target element.- Parameters:
text
- the target text that needs to be typed into the target webElementlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
typeSecure
@When("I Type {string} securely into the element found by {string}: {string}") public void typeSecure(String text, String locatorType, String locatorValue) Checks if there is any text in an element, clears it, then types the required string into the target element. Obfuscates the written text in the output report. This action should be used for writing passwords and secure text.- Parameters:
text
- the target text that needs to be typed into the target webElementlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
typeAppend
@When("I Append the text {string} to the element found by {string}: {string}") public void typeAppend(String text, String locatorType, String locatorValue) Appends the required string into the target element, regardless of the current text value.- Parameters:
text
- the target text that needs to be appended into the target webElementlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
typeFileLocationForUpload
@When("I Upload the file {string} to the element found by {string}: {string}") public void typeFileLocationForUpload(String absoluteFilePath, String locatorType, String locatorValue) ValidationEnums the required file path into an input[type='file'] button, to successfully upload the target file.- Parameters:
absoluteFilePath
- the full path to the file that needs to be uploadedlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
keyPress
@When("I Press the {string} key into the element found by {string}: {string}") public void keyPress(String key, String locatorType, String locatorValue) Sends a keypress to the target element. Supported keys are: ENTER, RETURN, TAB.- Parameters:
key
- the key that should be pressedlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
click
@When("I Click the element found by {string}: {string}") public void click(String locatorType, String locatorValue) Clicks on a certain element using Selenium WebDriver, or JavaScript.- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
clickAndHold
@When("I Click and hold the element found by {string}: {string}") public void clickAndHold(String locatorType, String locatorValue) Waits for the element to be clickable, and then clicks and holds it.- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
clipboardActions
@When("I use the clipboard to perform {string} on the element found by {string}: {string}") public void clipboardActions(String action, String locatorType, String locatorValue) Attempts to perform a native clipboard action on the text from a certain web element, like copy/cut/paste- Parameters:
action
- supports the following actions "copy", "paste", "cut", "select all", "unselect"locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
doubleClick
@When("I Double-click the element found by {string}: {string}") public void doubleClick(String locatorType, String locatorValue) Double-clicks on an element using Selenium WebDriver's Actions Library- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
dragAndDrop
@When("I Drag the element found by {string}: {string} and drop it on the element found by {string}: {string}") public void dragAndDrop(String sourceLocatorType, String sourceLocatorValue, String destinationLocatorType, String destinationLocatorValue) Drags the source element and drops it onto the destination element- Parameters:
sourceLocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}sourceLocatorValue
- the value/expression of the source element locator that's draggabledestinationLocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}destinationLocatorValue
- the value/expression of the target element locator that's droppable
-
dragAndDropByOffset
@When("I Drag the element found by {string}: {string} and drop it by offset x={int} and y={int}") public void dragAndDropByOffset(String locatorType, String locatorValue, int xOffset, int yOffset) Drags the source element and drops it onto the determined offset- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locatorxOffset
- the horizontal offset by which the element should be movedyOffset
- the vertical offset by which the element should be moved
-
hover
@When("I Hover over the element found by {string}: {string}") public void hover(String locatorType, String locatorValue) Hovers over target element.- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
select
@When("I Select {string} from the drop-down list element found by {string}: {string}") public void select(String text, String locatorType, String locatorValue) Selects an element from a dropdown list using its displayed text- Parameters:
text
- the text of the choice that you need to select from the target dropDown menulocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
setValueUsingJavaScript
@When("I Set the value {string} into the element found by {string}: {string}") public void setValueUsingJavaScript(String value, String locatorType, String locatorValue) Used to SetProperty value for an element (hidden or visible) using javascript- Parameters:
value
- the desired value that should be SetProperty for the target elementlocatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
submitFormUsingJavaScript
@When("I Submit the form found by {string}: {string}") public void submitFormUsingJavaScript(String locatorType, String locatorValue) Used to submit a form using javascript- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
waitForElementToBePresent
@When("I Wait for the element found by {string}: {string} to be present") public void waitForElementToBePresent(String locatorType, String locatorValue) Waits dynamically for a specific element to achieve the desired stateOfPresence on the current page. Waits for a specific number of retries multiplied by the default element identification timeout (in the POM.xml file)- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
waitForElementToBeNotPresent
@When("I Wait for the element found by {string}: {string} to be not present") public void waitForElementToBeNotPresent(String locatorType, String locatorValue) Waits dynamically for a specific element to achieve the desired stateOfPresence on the current page. Waits for a specific number of retries multiplied by the default element identification timeout (in the POM.xml file)- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locator
-
waitForTextToChange
@When("I Wait for the text inside the element found by {string}: {string} to change from the initial value {string}") public void waitForTextToChange(String locatorType, String locatorValue, String initialValue) Waits dynamically for a specific element's text to change from the initial value to a new unknown value. Waits for a specific number of retries multiplied by the default element identification timeout (in the POM.xml file)- Parameters:
locatorType
- can be {id, tagname, classname, name, linktext, partiallinktext, cssselector, xpath}locatorValue
- the value/expression of the desired element locatorinitialValue
- the initial text value of the target webElement
-