Class SeleniumGSpec
- java.lang.Object
-
- com.privalia.qa.specs.BaseGSpec
-
- com.privalia.qa.specs.SeleniumGSpec
-
public class SeleniumGSpec extends BaseGSpec
Steps definitions for selenium (web application automation)- Author:
- José Fernández
- See Also:
- https://www.selenium.dev/
-
-
Field Summary
-
Fields inherited from class com.privalia.qa.specs.BaseGSpec
commonspec
-
-
Constructor Summary
Constructors Constructor Description SeleniumGSpec(CommonG spec)
Generic constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertSeleniumHasAttributeValue(Integer index, String attribute, String value)
Verifies that a webelement previously found hasattribute
withvalue
(as a regexp)void
assertSeleniumIsDisplayed(Integer index, String option)
Verifies if a webelement previously found is displayed or notvoid
assertSeleniumIsEnabled(Integer index, String option)
Verifies if a webelement previously found is enabled or notvoid
assertSeleniumIsSelected(Integer index, String option)
Verifies if a webelement previously found is selected or notvoid
assertSeleniumNElementExists(String atLeast, Integer expectedCount, String method, String element)
Checks that the expected count of webelements are present in the page.void
assertSeleniumNElementExistsOnTimeOut(Integer timeout, Integer wait, Integer expectedCount, String method, String element)
Checks that the expected count of webelements are present in the page, within a timeout and with a location.void
assertSeleniumTextInSource(String text)
Checks if a text exists in the source of an already loaded URL.void
assertSeleniumTextOnElementPresent(Integer index, String text)
Verifies that a webelement previously found has the given textvoid
checkURL(String url)
Checks that we are in the URL passedvoid
checkURLContains(String text)
Checks if the current URL contains the specified textvoid
elementDeSelect(Integer index)
Choose no option from a select webelement found previouslyvoid
elementSelect(String option, Integer index)
Choose an @{code option} from a select webelement found previouslyvoid
goBackBrowserHistory(Integer numberOfPages)
void
goForwardBrowserHistory(Integer numberOfPages)
void
iAcceptTheAlert()
Accepts an alert message previously foundvoid
iDismissTheAlert()
Dismiss an alert message previously foundvoid
iExecuteTheScriptScriptOnTheElmentOnIndex(String script, String index, String enVar)
Executes a JavaScript function in the current driver.void
iGoToUrl(String url)
Directly navigate go to the specified urlvoid
iSaveTheValueOfThePropertyHrefOfTheElementInIndexInVariableVAR(String propertyName, int index, String variable)
Saves the given property of the specified webelement (referenced by its index) in the specified variable.void
iSetTheFileInSchemasEmptyJsonToTheElementOnIndex(String fileName, int index)
Assigns the given file (relative to schemas/) to the web elements in the given index.void
saveContentWebElementInEnvVar(Integer index, String envVar)
Takes the content of a webElement and stores it in the thread environment variable passed as parametervoid
saveSeleniumCookies()
Save cookie in context for future referencesvoid
scrollUntilElementVisible(String direction, int index)
Scrolls the page up or down until the element referenced by index is visiblevoid
scrollUntilElementVisibleByLocator(String direction, String method, String element, Integer index)
Directly scrolls the page up or down until the element is visiblevoid
seleniumBrowse(String isSecured, String path)
Browse tourl
using the current browser.void
seleniumChangeWindow()
Change current focus to another opened window.void
seleniumClear(Integer index)
Clear the text on a numberedindex
previously found element.void
seleniumClick(Integer index)
Click on an numberedurl
previously found element.void
seleniumClickByLocator(String method, String element, Integer index)
Directly clicks the given element referenced by locatorvoid
seleniumDoubleClick(Integer index)
Double clicks on an numberedurl
previously found element.void
seleniumDoubleClickByLocator(String method, String element, Integer index)
Directly double clicks the given element referenced by locatorvoid
seleniumDrag(String smethod, String source, String dmethod, String destination)
Search for two webelements dragging the first one to the secondvoid
seleniumGetwindows()
Assert that a new window is openvoid
seleniumHoverByLocator(String method, String element, Integer index)
Directly hovers on the given element referenced by locatorvoid
seleniumIdFrame(String method, String idframe)
Switch to the frame/iframe with the given locatorvoid
seleniumKeys(String text, Integer index)
Send astrokes
list on an numberedurl
previously found element or to the driver.void
seleniumMaximize()
Maximizes current browser window.void
SeleniumPause()
Temporally stop the execution of the featurevoid
seleniumRightClick(Integer index)
Right clicks on an numberedurl
previously found element.void
seleniumRightClickByLocator(String method, String element, Integer index)
Directly right clicks the given element referenced by locatorvoid
seleniumSnapshot()
Takes a snapshot/screenshot/screen capture of the current page.void
seleniumSwitchAParentFrame()
Switches to a parent frame/iframe.void
seleniumSwitchFrame(Integer index)
Switches to a frame/iframe.void
seleniumSwitchParentFrame()
Switches to the frames main container.void
seleniumType(String input, Integer index)
Type atext
on an numberedindex
previously found element.void
seleniumTypeByLocator(String input, String method, String element, Integer index)
Directly types the given text in the element referenced by locator.void
setupApp(String host)
Set app host and port.void
theElementOnIndexHasTextInCustomPropertyName(int index, String textValue, String customProperty)
Verifies if the value of a property of the webelement referenced by index matches the given valuevoid
waitAlertWithPooling(int poolingInterval, int poolMaxTime)
Checks if an alert message is open in the current page.void
waitWebElementWithPooling(int poolingInterval, int poolMaxTime, int elementsCount, String method, String element, String type)
Checks that a web elements exists in the page and if it is of the type specified in the given time interval.-
Methods inherited from class com.privalia.qa.specs.BaseGSpec
getCommonSpec
-
-
-
-
Constructor Detail
-
SeleniumGSpec
public SeleniumGSpec(CommonG spec)
Generic constructor.- Parameters:
spec
- object
-
-
Method Detail
-
setupApp
@Given("^My app is running in \'(.*)\'$") public void setupApp(String host)
Set app host and port.This is an initialization step. This is used as the first step in Selenium features to configure the basepath url. This step does not directly take the user to the given url, just sets the base url that is later used in
seleniumBrowse(String, String)
. You can also checkiGoToUrl(String)
Example:
Given My app is running in 'demoqa.com:80'
- Parameters:
host
- host where app is running (i.e "localhost" or "localhost:443")- See Also:
seleniumBrowse(String, String)
,iGoToUrl(String)
-
seleniumBrowse
@Given("^I( securely)? browse to \'(.*)\'$") public void seleniumBrowse(String isSecured, String path)
Browse tourl
using the current browser.The
url
is relative to the basepath configured withsetupApp(String)
method. You can also useiGoToUrl(String)
to directly navigate to the given url.Example:
Given My app is running in 'demoqa.com:80' Then I browse to '/' //will load http://demoqa.com:80/ Then I browse to '/login' //will load http://demoqa.com:80/login
Or if the site uses httpsGiven My app is running in 'mysecuresite.com:443' Then I securely browse to '/' //will load https://mysecuresite.com:443/
- Parameters:
isSecured
- If the connection should be securedpath
- path of running app- See Also:
setupApp(String)
,iGoToUrl(String)
-
waitWebElementWithPooling
@Then("^I check every \'(\\d+)\' seconds for at least \'(\\d+)\' seconds until \'(\\d+)\' elements exists with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\' and is \'(visible|clickable|present|hidden)\'$") public void waitWebElementWithPooling(int poolingInterval, int poolMaxTime, int elementsCount, String method, String element, String type)
Checks that a web elements exists in the page and if it is of the type specified in the given time interval.This method is similar to
assertSeleniumNElementExists(String, Integer, String, String)
but implements a pooling mechanism with a maximum pooling time instead of a static waitExample:
Then in less than '10' seconds, checking each '1' seconds, '1' elements exists with 'id:name_3_firstname'
- Parameters:
poolingInterval
- Time between consecutive condition evaluationspoolMaxTime
- Maximum time to wait for the condition to be trueelementsCount
- integer. Expected number of elements.method
- class of element to be searchedelement
- webElement searched in selenium contexttype
- The expected style of the element: visible, clickable, present, hidden- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
-
waitAlertWithPooling
@Then("^I check every \'(\\d+)\' seconds for at least \'(\\d+)\' seconds until an alert appears$") public void waitAlertWithPooling(int poolingInterval, int poolMaxTime)
Checks if an alert message is open in the current page. The function implements a pooling interval to check if the condition is trueThis step stores the reference to the alert to be used in other steps such as
iAcceptTheAlert()
or byiDismissTheAlert()
Example:
And I check every '1' seconds for at least '5' seconds until an alert appears
- Parameters:
poolingInterval
- Time between consecutive condition evaluationspoolMaxTime
- Maximum time to wait for the condition to be true- See Also:
iAcceptTheAlert()
,iDismissTheAlert()
-
iAcceptTheAlert
@Then("^I dismiss the alert$") public void iAcceptTheAlert()
Accepts an alert message previously foundExample:
And I check every '1' seconds for at least '5' seconds until an alert appears And I dismiss the alert
- See Also:
waitAlertWithPooling(int, int)
,iAcceptTheAlert()
-
iDismissTheAlert
@Then("^I accept the alert$") public void iDismissTheAlert()
Dismiss an alert message previously foundExample:
And I check every '1' seconds for at least '5' seconds until an alert appears And I accept the alert
- See Also:
waitAlertWithPooling(int, int)
,iDismissTheAlert()
-
iSetTheFileInSchemasEmptyJsonToTheElementOnIndex
@Then("^I assign the file in \'(.*)\' to the element on index \'(\\d+)\'$") public void iSetTheFileInSchemasEmptyJsonToTheElementOnIndex(String fileName, int index)
Assigns the given file (relative to schemas/) to the web elements in the given index.This step is suitable for file selectors/file pickers (an input type=file), where the user must specify a file in the local computer as an input in a form. This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:profile_pic_10' Then I assign the file in 'schemas/empty.json' to the element on index '0'
- Parameters:
fileName
- Name of the file relative to schemas folder (schemas/myFile.txt)index
- Index of the web element (file input)
-
seleniumMaximize
@Given("^I maximize the browser$") public void seleniumMaximize()
Maximizes current browser window. Mind the current resolution could break a test.Example:
Then I maximize the browser
-
seleniumSwitchFrame
@Given("^I switch to the iframe on index \'(\\d+)\'$") public void seleniumSwitchFrame(Integer index)
Switches to a frame/iframe.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:iframeResult' Then I switch to the iframe on index '0'
- Parameters:
index
- the index
-
seleniumIdFrame
@Given("^I switch to iframe with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\'$") public void seleniumIdFrame(String method, String idframe)
Switch to the frame/iframe with the given locatorExample:
Then I switch to iframe with 'id:iframeResult'
- Parameters:
method
- the method (id, class, name, xpath)idframe
- locator
-
seleniumSwitchAParentFrame
@Given("^I switch to a parent frame$") public void seleniumSwitchAParentFrame()
Switches to a parent frame/iframe.Example:
Then I switch to a parent frame
-
seleniumSwitchParentFrame
@Given("^I switch to the main frame container$") public void seleniumSwitchParentFrame()
Switches to the frames main container.Example:
Then I switch to the main frame container
-
seleniumGetwindows
@Given("^a new window is opened$") public void seleniumGetwindows()
Assert that a new window is openThis step verifies that at least one new window is open. You can switch focus to this new window using the step
seleniumChangeWindow()
Example:
Then a new window is opened
- See Also:
seleniumChangeWindow()
-
assertSeleniumTextOnElementPresent
@Then("^the element on index \'(\\d+)\' has \'(.*)\' as text$") public void assertSeleniumTextOnElementPresent(Integer index, String text)
Verifies that a webelement previously found has the given textThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'xpath://*[@id="pie_register"]/li[6]/div/label' And the element on index '0' has 'Phone Number' as text
- Parameters:
index
- the index of the webelementtext
- the text to verify
-
assertSeleniumTextInSource
@Then("^this text exists:$") public void assertSeleniumTextInSource(String text)
Checks if a text exists in the source of an already loaded URL.Example:
Then this text exists: """ <h1 class="entry-title">Home</h1> """
- Parameters:
text
- the text to verify
-
assertSeleniumNElementExists
@Then("^(at least )?\'(\\d+)\' elements? exists? with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\'$") public void assertSeleniumNElementExists(String atLeast, Integer expectedCount, String method, String element)
Checks that the expected count of webelements are present in the page.Elements found are internally stored to be used in subsequent steps in the same scenario
Example:
When '1' elements exists with 'id:profile_pic_10'
Elements can be also located using class for example:When '7' elements exists with 'class:legend_txt'
To verify that the amount of elements is bigger or equal:Then at least '1' elements exists with 'class:detail-entry'
Elements are stored to be used in subsequent steps:Given '1' elements exists with 'xpath://*[@id="myBtn"]' Then I click on the element on index '0'
- Parameters:
atLeast
- asserts that the amount of elements if greater or equal to expectedCount. If null, asserts the amount of element is equal to expectedCountexpectedCount
- the expected count of elements to findmethod
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the element- See Also:
seleniumClick(Integer)
-
assertSeleniumNElementExistsOnTimeOut
@Then("^in less than \'(\\d+)\' seconds, checking each \'(\\d+)\' seconds, \'(\\d+)\' elements exists with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\'$") public void assertSeleniumNElementExistsOnTimeOut(Integer timeout, Integer wait, Integer expectedCount, String method, String element) throws InterruptedException
Checks that the expected count of webelements are present in the page, within a timeout and with a location.Each negative lookup is followed by a wait of
wait
seconds. Selenium times are not accounted for the mentioned timeout. This method is similar towaitWebElementWithPooling(int, int, int, String, String, String)
but uses static wait instead ofFluentWait
and does not assert the expected condition of the elements (if elements are visible|hidden|present|clickable)Example:
Then in less than '20' seconds, checking each '2' seconds, '1' elements exists with 'id:name_3_firstname' And I click on the element on index '0'
- Parameters:
timeout
- The max time to wait for the condition to be truewait
- Interval between verificationexpectedCount
- The expected count of elementsmethod
- The methodelement
- The web element element- Throws:
InterruptedException
- The interrupted exception- See Also:
waitAlertWithPooling(int, int)
,seleniumClick(Integer)
-
assertSeleniumIsDisplayed
@Then("^the element on index \'(\\d+?)\' (IS|IS NOT) displayed$") public void assertSeleniumIsDisplayed(Integer index, String option)
Verifies if a webelement previously found is displayed or notThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:myDIV' And the element on index '0' IS displayed
Or:When '1' elements exists with 'id:myDIV' And the element on index '0' IS NOT displayed
- Parameters:
index
- the index of the elementoption
- the option (is selected or not)- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
assertSeleniumIsEnabled
@Then("^the element on index \'(\\d+?)\' (IS|IS NOT) enabled$") public void assertSeleniumIsEnabled(Integer index, String option)
Verifies if a webelement previously found is enabled or notThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'xpath://*[@id="myBtn"]' And the element on index '0' IS enabled
Or:When '1' elements exists with 'xpath://*[@id="myBtn"]' And the element on index '0' IS NOT enabled
- Parameters:
index
- the index of the web element in the listoption
- the option (is enabled or not)
-
assertSeleniumIsSelected
@Then("^the element on index \'(\\d+?)\' (IS|IS NOT) selected$") public void assertSeleniumIsSelected(Integer index, String option)
Verifies if a webelement previously found is selected or notThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '3' elements exists with 'name:radio_4[]' And the element on index '0' IS NOT selected
Or:When '3' elements exists with 'name:radio_4[]' And the element on index '1' IS selected
- Parameters:
index
- the index of the web element in the listoption
- the option (if it is enabled or not)
-
assertSeleniumHasAttributeValue
@Then("^the element on index \'(\\d)\' has \'(id|name|class|css|xpath|linkText|partialLinkText|tagName)\' as \'(.*)\'$") public void assertSeleniumHasAttributeValue(Integer index, String attribute, String value)
Verifies that a webelement previously found hasattribute
withvalue
(as a regexp)This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:phone_9' Then the element on index '0' has 'id' as 'phone_9'
- Parameters:
index
- the index of the web elementattribute
- the attribute to verifyvalue
- the value of the attribute
-
seleniumSnapshot
@Then("^I take a snapshot$") public void seleniumSnapshot()
Takes a snapshot/screenshot/screen capture of the current page.Snapshots are stored under target/executions
Example:
Then I take a snapshot
-
checkURL
@Then("^we are in page \'(.*)\'$") public void checkURL(String url)
Checks that we are in the URL passedExample:
Given I go to 'https://demoqa.com/' Then we are in page 'https://demoqa.com/'
- Parameters:
url
- the url to verify
-
checkURLContains
@Then("^the current url contains the text \'(.*)\'$") public void checkURLContains(String text)
Checks if the current URL contains the specified textExample:
Given My app is running in 'demoqa.com:80' And I browse to '/autocomplete' Then the current url contains the text 'autocomplete'
- Parameters:
text
- Text to look for in the current url
-
saveSeleniumCookies
@Then("^I save selenium cookies in context$") public void saveSeleniumCookies()
Save cookie in context for future references
-
saveContentWebElementInEnvVar
@Then("^I save content of element in index \'(\\d+)\' in environment variable \'(.*)\'$") public void saveContentWebElementInEnvVar(Integer index, String envVar)
Takes the content of a webElement and stores it in the thread environment variable passed as parameterThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:my_text_field' I save content of element in index '0' in environment variable 'mytext'
- Parameters:
index
- position of the element in the array of webElements foundenvVar
- name of the thread environment variable where to store the text- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
theElementOnIndexHasTextInCustomPropertyName
@Then("^the element in index \'(.*)\' has \'(.*)\' in property \'(.*)\'$") public void theElementOnIndexHasTextInCustomPropertyName(int index, String textValue, String customProperty)
Verifies if the value of a property of the webelement referenced by index matches the given valueThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
And '3' elements exists with 'css:input[name='radio_4[]']' Then the element in index '1' has 'radio_4[]' in property 'name'
- Parameters:
index
- Position of the element in the array of webElementstextValue
- Value expected in the propertycustomProperty
- Property of webElement to verify- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
seleniumDrag
@When("^I drag \'(.*):(.*)\' and drop it to \'(.*):(.*)\'$") public void seleniumDrag(String smethod, String source, String dmethod, String destination)
Search for two webelements dragging the first one to the second- Parameters:
smethod
- the smethodsource
- initial web elementdmethod
- the dmethoddestination
- destination web element
-
seleniumClick
@When("^I click on the element on index \'(\\d+)\'$") public void seleniumClick(Integer index)
Click on an numberedurl
previously found element.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
. You can also perform click action on an element usingseleniumClickByLocator(String, String, Integer)
Example:
When '1' elements exists with 'xpath://*[@id="name_3_lastname"]' And I click on the element on index '0'
- Parameters:
index
- Index of the webelement in the list- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
,seleniumClickByLocator(String, String, Integer)
-
seleniumDoubleClick
@When("^I double click on the element on index \'(\\d+)\'$") public void seleniumDoubleClick(Integer index)
Double clicks on an numberedurl
previously found element.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
.Example:
When '1' elements exists with 'id:doubleClickBtn' And I double click on the element on index '0'
- Parameters:
index
- Index of the webelement in the list- See Also:
seleniumDoubleClickByLocator(String, String, Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
seleniumRightClick
@When("^I right click on the element on index \'(\\d+)\'$") public void seleniumRightClick(Integer index)
Right clicks on an numberedurl
previously found element.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
.Example:
When '1' elements exists with 'id:rightClickBtn' And I right click on the element on index '0'
- Parameters:
index
- Index of the webelement in the list- See Also:
seleniumRightClickByLocator(String, String, Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
seleniumClear
@When("^I clear the content on text input at index \'(\\d+)\'$") public void seleniumClear(Integer index)
Clear the text on a numberedindex
previously found element.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
Then the element on index '0' has 'id' as 'phone_9' And I type '555-555' on the element on index '0' And I clear the content on text input at index '0'
- Parameters:
index
- index of the web element- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
seleniumType
@When("^I type \'(.*)\' on the element on index \'(\\d+)\'$") public void seleniumType(String input, Integer index)
Type atext
on an numberedindex
previously found element.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
You can also use the stepseleniumTypeByLocator(String, String, String, Integer)
to directly type the given text in the elementExample:
Then the element on index '0' has 'id' as 'phone_9' And I type '555-555' on the element on index '0' And I clear the content on text input at index '0'
- Parameters:
input
- Text to write on the elementindex
- Index of the webelement in the list- See Also:
seleniumTypeByLocator(String, String, String, Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
seleniumKeys
@When("^I send \'(.*)\' on the element on index \'(\\d+)\'$") public void seleniumKeys(String text, Integer index)
Send astrokes
list on an numberedurl
previously found element or to the driver.Strokes examples are "HOME, END" or "END, SHIFT + HOME, DELETE". Each element in the stroke list has to be an element from
Keys
(NULL, CANCEL, HELP, BACK_SPACE, TAB, CLEAR, RETURN, ENTER, SHIFT, LEFT_SHIFT, CONTROL, LEFT_CONTROL, ALT, LEFT_ALT, PAUSE, ESCAPE, SPACE, PAGE_UP, PAGE_DOWN, END, HOME, LEFT, ARROW_LEFT, UP, ARROW_UP, RIGHT, ARROW_RIGHT, DOWN, ARROW_DOWN, INSERT, DELETE, SEMICOLON, EQUALS, NUMPAD0, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, MULTIPLY, ADD, SEPARATOR, SUBTRACT, DECIMAL, DIVIDE, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, META, COMMAND, ZENKAKU_HANKAKU) , a plus sign (+), a comma (,) or spaces ( )
This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
When '1' elements exists with 'id:name_3_firstname' Then I type 'testUser' on the element on index '0' Then I send 'ENTER' on the element on index '0'
- Parameters:
text
- key stroke to sendindex
- index of the web element in the list- See Also:
seleniumType(String, Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
elementSelect
@When("^I select \'(.*)\' on the element on index \'(\\d+)\'$") public void elementSelect(String option, Integer index)
Choose an @{code option} from a select webelement found previouslyThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
- Parameters:
option
- option in the select elementindex
- index of the web element in the list- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
elementDeSelect
@When("^I de-select every item on the element on index \'(\\d+)\'$") public void elementDeSelect(Integer index)
Choose no option from a select webelement found previouslyThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
- Parameters:
index
- index of the web element in the list
-
seleniumChangeWindow
@When("^I change active window$") public void seleniumChangeWindow()
Change current focus to another opened window.All further selenium actions will be executed in this new window. You can use the step
seleniumGetwindows()
to assert that a new window is indeed openExample:
Given a new window is opened Then I change active window
- See Also:
seleniumGetwindows()
-
iSaveTheValueOfThePropertyHrefOfTheElementInIndexInVariableVAR
@Then("^I save the value of the property \'(.*)\' of the element in index \'(.*)\' in variable \'(.*)\'$") public void iSaveTheValueOfThePropertyHrefOfTheElementInIndexInVariableVAR(String propertyName, int index, String variable)
Saves the given property of the specified webelement (referenced by its index) in the specified variable.This step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
Then '1' elements exists with 'id:menu-item-146' Then I save the value of the property 'class' of the element in index '0' in variable 'VAR2'
- Parameters:
propertyName
- Name of the propertyindex
- Index of the webelement in the listvariable
- Variable where to save the result- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
iExecuteTheScriptScriptOnTheElmentOnIndex
@Then("^I execute \'(.*)\' as javascript( on the element on index \'(.*)\')?( and save the result in the environment variable \'(.*)\')?$") public void iExecuteTheScriptScriptOnTheElmentOnIndex(String script, String index, String enVar)
Executes a JavaScript function in the current driver. This could be useful for getting specific information on the web page or forcing specific actions, like clicking on an element that is being blocked by a popupThis step requires a previous operation for finding elements to have been executed, such as:
assertSeleniumNElementExists(String, Integer, String, String)
assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
waitWebElementWithPooling(int, int, int, String, String, String)
Example:
And I execute 'alert("This is an alert!")' as javascript
Javascript functions can be executed on previous found elements:And '1' elements exists with 'xpath://*[@id="menu-item-158"]/a' And I execute 'arguments[0].click();' as javascript on the element on index '0'
- Parameters:
script
- Script to execute (i.e alert("This is an alert message"))index
- If used, the index of the previously found web element on which to execute the functionenVar
- If used, variable where to store the result of the execution of the script- See Also:
assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
,waitWebElementWithPooling(int, int, int, String, String, String)
-
iGoToUrl
@Given("I go to \'(.*)\'") public void iGoToUrl(String url)
Directly navigate go to the specified urlThis step is a similar way of navigating to a web page by specifying the full url directly, instead of first setting the base path with
setupApp(String)
and later navigate withseleniumBrowse(String, String)
Example:
Given I go to 'http://www.demoqa.com/autocomplete'
You can also do it like this:Given My app is running in 'demoqa.com:80' And I browse to '/autocomplete'
- Parameters:
url
- Url were to navigate- See Also:
setupApp(String)
,seleniumBrowse(String, String)
-
seleniumClickByLocator
@Then("^I click on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$") public void seleniumClickByLocator(String method, String element, Integer index)
Directly clicks the given element referenced by locatorThis step performs a click action on the element. This step is similar to
seleniumClick(Integer)
but, it does not require a previous operation for finding elements, such asassertSeleniumNElementExists(String, Integer, String, String)
orassertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
. If the page contains several web elements with the given locator, the click action will be performed to the first element found by default, unless an index is specified (first element has index 0)Example: Perform click on the element with id 'username'
When I click on the element with 'id:username'
Example: Using index in case more than one element is found (first element has index 0)When I click on the element with 'tagName:button' index 1 //clicks the second element with tag name 'button'
- Parameters:
method
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)- See Also:
seleniumClick(Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
-
seleniumTypeByLocator
@When("^I type \'(.*)\' on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$") public void seleniumTypeByLocator(String input, String method, String element, Integer index)
Directly types the given text in the element referenced by locator.This steps types the given text on the given web element. This step is similar to
seleniumType(String, Integer)
but, it does not require a previous operation for finding elements, such asassertSeleniumNElementExists(String, Integer, String, String)
orassertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
. If the page contains several web elements with the given locator, the click action will be performed to the first element found by default, unless an index is specified (first element has index 0)Example: Type 555-555 in the input field with id:phone_number
And I type '555-555' on the element with 'id:phone_number'
Example: Using index in case more than one element is found (first element has index 0)And I type '555-555' on the element with 'class:text-field' index 1
- Parameters:
input
- text to type in the elementmethod
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)- See Also:
seleniumType(String, Integer)
-
goBackBrowserHistory
@And("^I go back (\\d+) (?:page|pages)?$") public void goBackBrowserHistory(Integer numberOfPages)
-
goForwardBrowserHistory
@And("^I go forward (\\d+) (?:page|pages)?$") public void goForwardBrowserHistory(Integer numberOfPages)
-
scrollUntilElementVisible
@Then("^I scroll (up|down) until the element on index \'(\\d+)\' is visible$") public void scrollUntilElementVisible(String direction, int index) throws InterruptedException
Scrolls the page up or down until the element referenced by index is visibleThis step executes a javascript function to automatically scroll the element into view. The web element is referenced by its index, to it does require a previous operation for finding elements, such as
assertSeleniumNElementExists(String, Integer, String, String)
orassertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
to be executed first.Example: Scroll until the submit button is visible, then, click on it
And at least '1' elements exists with 'id:submit' Then I scroll down until the element on index '0' is visible Then I click on the element on index '0'
- Parameters:
direction
- Indicates if the scroll is upwards or downwardsindex
- Index of the web element- Throws:
InterruptedException
- InterruptedException- See Also:
scrollUntilElementVisibleByLocator(String, String, String, Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
-
scrollUntilElementVisibleByLocator
@Then("^I scroll (up|down) until the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? is visible$") public void scrollUntilElementVisibleByLocator(String direction, String method, String element, Integer index) throws InterruptedException
Directly scrolls the page up or down until the element is visibleThis step executes a javascript function to automatically scroll the element into view. This step is similar to
scrollUntilElementVisible(String, int)
but it does not require a previous operation for finding elements to be executed, since the element is directly referenced as a locatorExample: Scroll up and down the page until the referenced element is visible
Then I scroll up until the element with 'id:userName' is visible Then I scroll down until the element with 'id:submit' is visible Then I click on the element with 'id:submit'
- Parameters:
direction
- Indicates if the scroll is upwards or downwardsmethod
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- The relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)- Throws:
InterruptedException
- InterruptedException- See Also:
scrollUntilElementVisible(String, int)
-
seleniumDoubleClickByLocator
@Then("^I double click on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$") public void seleniumDoubleClickByLocator(String method, String element, Integer index)
Directly double clicks the given element referenced by locatorThis step performs a double click action on the element. This step is similar to
seleniumDoubleClick(Integer)
but, it does not require a previous operation for finding elements, such asassertSeleniumNElementExists(String, Integer, String, String)
orassertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
. If the page contains several web elements with the given locator, the double click action will be performed to the first element found by default, unless an index is specified (first element has index 0)Example: Perform double click on the element with id 'doubleClickBtn'
When I double click on the element with 'id:doubleClickBtn'
Example: Using index in case more than one element is found (first element has index 0)When I double click on the element with 'tagName:button' index 1 //clicks the second element with tag name 'button'
- Parameters:
method
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)- See Also:
seleniumDoubleClick(Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
-
seleniumRightClickByLocator
@Then("^I right click on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$") public void seleniumRightClickByLocator(String method, String element, Integer index)
Directly right clicks the given element referenced by locatorThis step performs a right click action on the element. This step is similar to
seleniumRightClick(Integer)
but, it does not require a previous operation for finding elements, such asassertSeleniumNElementExists(String, Integer, String, String)
orassertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
. If the page contains several web elements with the given locator, the right click action will be performed to the first element found by default, unless an index is specified (first element has index 0)Example: Perform right click on the element with id 'rightClickBtn'
When I right click on the element with 'id:rightClickBtn'
Example: Using index in case more than one element is found (first element has index 0)When I right click on the element with 'tagName:button' index '1' //clicks the second element with tag name 'button'
- Parameters:
method
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)- See Also:
seleniumRightClick(Integer)
,assertSeleniumNElementExists(String, Integer, String, String)
,assertSeleniumNElementExistsOnTimeOut(Integer, Integer, Integer, String, String)
-
seleniumHoverByLocator
@Then("^I hover on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$") public void seleniumHoverByLocator(String method, String element, Integer index)
Directly hovers on the given element referenced by locatorThis step performs the function of hovering, or, directly placing the cursor (mouse pointer) on top of the specified element. This is particularly useful since in some situations, DOM elements are only revealed after the mouse is directly placed on top of another element (like tooltips)
Example:
Given I hover on the element with 'id:revelPopUpButton'
Example: Using index in case more than one element is found (first element has index 0)Given I hover on the element with 'id:revelPopUpButton' index '1' //clicks the second element with tag name 'button'
- Parameters:
method
- method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)element
- the relative reference to the elementindex
- Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
-
SeleniumPause
@Then("^I pause$") public void SeleniumPause()
Temporally stop the execution of the featureThis step shows a dialog in the center of the screen and interrupts the execution of the rest of the steps in the feature until the "Ok" button in the dialog is pressed. This comes handy when debugging and the user needs to execute some manual actions before continuing
Example:
Given I go to 'http://demoqa.com/automation-practice-form' Then I pause //This will show the pause dialog Then I type 'Jose' on the element with 'id:firstName' //This will only be executed when the "Ok" button in previous dialog is pressed
-
-