Class SeleniumGSpec


  • public class SeleniumGSpec
    extends BaseGSpec
    Steps definitions for selenium (web application automation). Check the examples provided on each method to know how to use them in your own Feature files.
    Author:
    José Fernández
    See Also:
    https://www.selenium.dev/
    • Constructor Detail

      • SeleniumGSpec

        public SeleniumGSpec​(CommonG spec)
        Generic constructor.
        Parameters:
        spec - object
    • Method Detail

      • setupApp

        @Deprecated
        @Given("^My app is running in \'(.*)\'$")
        public void setupApp​(String host)
        Deprecated.
        This method is deprecated, use iGoToUrl(String) instead
        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). Notice that is not necessary to specify http:// or https://, this is automatically inferred when using seleniumBrowse(String, String), check this step for more concrete examples.
        You can also consider using iGoToUrl(String) instead. This step just navigates the user to the given full URL and can be easier to read in the gherkin files

        
         Example:
        
         Scenario: setting http://demoqa.com:80 as basepath
              Given My app is running in 'demoqa.com:80'
              When I browse to '/login'
         
        Parameters:
        host - host where app is running (i.e "localhost" or "localhost:443")
        See Also:
        seleniumBrowse(String, String), iGoToUrl(String)
      • seleniumBrowse

        @Deprecated
        @Given("^I( securely)? browse to \'(.*)\'$")
        public void seleniumBrowse​(String isSecured,
                                   String path)
        Deprecated.
        This method is deprecated, use iGoToUrl(String) instead
        Browse to url using the current browser.

        The url is relative to the basepath configured with setupApp(String) method. You can also use iGoToUrl(String) to directly navigate to the given url.

        
         Example:
        
         Scenario: Navigating to http://demoqa.com:80/login
              Given My app is running in 'demoqa.com:80'
              Then I browse to '/'
              Then I browse to '/login'
        
         Scenario: Navigating using https
              Given My app is running in 'mysecuresite.com:443'
              Then I securely browse to '/'
         
        Parameters:
        isSecured - If the connection should be secured
        path - 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.

        Elements found are internally stored to be used in subsequent steps in the same scenario. This method is similar to assertSeleniumNElementExists(String, Integer, String, String)
        but implements a pooling mechanism with a maximum pooling time instead of a static wait

        
         Example:
        
         Scenario: Wait for element to be present/visible/hidden/clickable (longer method)
               Given I go to 'http://localhost/styled/javascript-redirect-test.html'
               And I click on the element with 'id:delaygotobasic'
               Then I check every '1' seconds for at least '10' seconds until '1' elements exists with 'id:goback' and is 'clickable'
               And I click on the element with 'id:goback'
               And we are in page 'http://localhost/styled/javascript-redirect-test.html'
         
        Parameters:
        poolingInterval - Time between consecutive condition evaluations
        poolMaxTime - Maximum time to wait for the condition to be true
        elementsCount - integer. Expected number of elements.
        method - class of element to be searched
        element - webElement searched in selenium context
        type - The expected style of the element: visible, clickable, present, hidden
        See Also:
        seleniumBrowse(String, String), assertSeleniumNElementExists(String, Integer, String, String), seleniumClick(Integer)
      • waitWebElement

        @Then("^I wait until element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\' is present")
        public void waitWebElement​(String method,
                                   String element)
        Waits for the given element to be present on the page

        This step can be seen as a shorter and more compact version than waitWebElementWithPooling(int, int, int, String, String, String). It is useful in cases where a given element may take time to appear (like when loading a new page). This step will check every second for a max of 10 seconds. If the element is not found before 10 secs, the step fails. If you need to wait more time than 10 seconds you can try using waitWebElementWithTime(int, String, String)

        
         Example:
        
         Scenario: Wait until the element is present
              Given I go to 'http://demoqa.com/text-box'
              And I wait until element with 'id:userName' is present
              And I type 'John' on the element with 'id:userName'
         
        Parameters:
        method - Method to locate the element (id, name, class, css, xpath, linkText, partialLinkText, tagName)
        element - locator
        See Also:
        waitWebElementWithPooling(int, int, int, String, String, String), waitWebElementWithTime(int, String, String)
      • waitWebElementWithTime

        @Then("^I wait \'(.*)\' seconds until element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*)\' is present")
        public void waitWebElementWithTime​(int maxTime,
                                           String method,
                                           String element)
        Waits for the given element to be present on the page

        Similar to waitWebElement(String, String) but with the ability for configuring the time to wait.

        
         Example:
        
         Scenario: Wait until the element is present
              Given I go to 'http://demoqa.com/text-box'
              Then I wait '10' seconds until element with 'id:userName' is present
              And I type 'John' on the element with 'id:userName'
         
        Parameters:
        maxTime - Max time to wait
        method - Method to locate the element (id, name, class, css, xpath, linkText, partialLinkText, tagName)
        element - locator
        See Also:
        waitWebElementWithPooling(int, int, int, String, String, String), waitWebElement(String, String)
      • waitAlert

        @Then("^I wait \'(\\d+)\' seconds until an alert appears$")
        public void waitAlert​(int poolMaxTime)
        Checks if an alert message is open in the current page.

        This step stores the reference to the alert to be used in other steps such as iAcceptTheAlert() or by iDismissTheAlert()

        
         Example:
        
          Scenario: Wait for an alert to appear
               Given I go to 'https://demoqa.com/alerts'
               When I click on the element with 'id:alertButton'
               And I wait '5' seconds until an alert appears
         
        Parameters:
        poolMaxTime - 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 found.

        This step will automatically wait for 5 seconds until the alert is present. If that is not enough, you can directly use waitAlert(int)

        
         Example:
        
         Scenario: Wait for an alert and dismiss it
              Given I go to 'http://mydummysite.com/login'
              And I dismiss the alert
         
        See Also:
        waitAlert(int), iAcceptTheAlert()
      • iDismissTheAlert

        @Then("^I accept the alert$")
        public void iDismissTheAlert()
        Dismiss an alert message previously found.

        This step will automatically wait 5 seconds for the alert to be present. If thats not enough, you can use waitAlert(int)

        
         Example:
        
         Scenario: Wait for an alert and accept it
              Given I go to 'http://mydummysite.com/login'
              And I check every '1' seconds for at least '5' seconds until an alert appears
              And I accept the alert
         
         
        See Also:
        waitAlert(int), iDismissTheAlert()
      • iSetTheFileInSchemasEmptyJsonToTheElementOnIndex

        @Then("^I assign the file in \'(.*)\' to the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$")
        public void iSetTheFileInSchemasEmptyJsonToTheElementOnIndex​(String fileName,
                                                                     String method,
                                                                     String element,
                                                                     Integer index)
        Assigns the given file (relative to schemas/) to the referenced web element.

        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.

        
         Example:
        
         Scenario: Uploading a new profile picture
               Given I go to 'http://localhost/styled/file-upload-test.html'
               And '1' elements exists with 'id:fileinput'
               When I assign the file in 'schemas/empty.json' to the element with 'id:fileinput'
               Then I click on the element with 'name:upload'
               And the element with 'id:uploadedfilename' has 'empty.json' as text
         
        Parameters:
        fileName - Name of the file relative to schemas folder (schemas/myFile.txt)
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        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:
        
         Scenario: maximize the browser
              Then I maximize the browser
         
      • 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 locator.
        
         Example:
        
         Scenario: Switch to iframe by locator
              Given I go to 'http://mydummysite.com/
              Then I switch to iframe with 'id:iframeResult'
         
        Parameters:
        method - the method (id, class, name, xpath)
        idframe - locator
        See Also:
        seleniumSwitchFrame(Integer)
      • seleniumGetwindows

        @Given("^a new window is opened$")
        public void seleniumGetwindows()
        Assert that a new window is open

        This step verifies that at least one new window is open. You can switch focus to this new window using the step seleniumChangeWindow()

        
         Example:
        
         Scenario: Check that a new window opened
              Given I go to 'http:mydummysite/index.html'
              Then I click on the element with 'name:pie_submit'
              Then a new window is opened
         
        See Also:
        seleniumChangeWindow()
      • assertSeleniumTextOnElementByLocatorPresent

        @Then("^the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? has \'(.*)\' as text( ignoring case)?$")
        public void assertSeleniumTextOnElementByLocatorPresent​(String method,
                                                                String element,
                                                                Integer index,
                                                                String text,
                                                                String ignoreCase)
        Verifies that a webelement previously found has the given text
        
         Example:
        
         Scenario: Verify text of element
              Given I go to 'https://demoqa.com/text-box'
              And the element with 'id:userName-label' has 'Full Name' as text
              And the element with 'class:form-label' index '1' has 'Email' as text
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        text - Text to locate
        ignoreCase - Whether to ignore case or not when checking the text
      • assertSeleniumTextInSource

        @Then("^this text exists:$")
        public void assertSeleniumTextInSource​(String text)
        Checks if a text exists in the source of an already loaded URL.
        
         Example:
        
         Scenario: Verify text exists in page source
              Given I go to 'http:mydummysite/index.html'
              Then this text exists:
              """
              <h1 class="entry-title">Home</h1>
              """
         
        Parameters:
        text - the text to verify
      • assertSeleniumTextInSourceIgnoreCase

        @Then("^this text exists ignoring case:$")
        public void assertSeleniumTextInSourceIgnoreCase​(String text)
        Checks if a text exists in the source of an already loaded URL ignoring case.
        
         Example:
        
         Scenario: Verify text exists in page source
              Given I go to 'http:mydummysite/index.html'
              Then this text exists:
              """
              <h1 class="entry-title">Home</h1>
              """
         
        Parameters:
        text - the text to verify
      • assertSeleniumTextNotPresentInSource

        @Then("^this text does not exist:$")
        public void assertSeleniumTextNotPresentInSource​(String text)
        Checks if a text does not exist in the source of an already loaded URL.
        
         Example:
        
         Scenario: Verify text exists in page source
              Given I go to 'http:mydummysite/index.html'
              Then this text does not exist:
              """
              <h1 class="entry-title">Not present text</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

        
         Examples:
        
         Scenario: Verify element exists on the page
               Given I go to 'http://localhost/styled/find-by-playground-test.html'
               Then '1' elements exists with 'id:p1'
               Then '2' elements exists with 'name:pName2'
               Then '118' elements exists with 'class:normal'
               Then at least '1' elements exists with 'class:explanation'
         
         
        Parameters:
        atLeast - asserts that the amount of elements if greater or equal to expectedCount. If null, asserts the amount of element is equal to expectedCount
        expectedCount - the expected count of elements to find
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        See Also:
        waitWebElementWithPooling(int, int, int, String, String, String), seleniumClick(Integer)
      • assertSeleniumIsDisplayedByLocator

        @Then("^the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? (IS|IS NOT) displayed$")
        public void assertSeleniumIsDisplayedByLocator​(String method,
                                                       String element,
                                                       Integer index,
                                                       String option)
        Verifies if a webelement referenced by locator is displayed or not
        
         Example:
        
         Scenario: Verify element is displayed
               Given I go to 'https://demoqa.com/accordian'
               And the element with 'id:section1Content' IS displayed
               And the element with 'id:section2Content' index '0' IS NOT displayed
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        option - Whether the element IS or IS NOT displayed
        See Also:
        assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String)
      • assertSeleniumIsEnabledByLocator

        @Then("^the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? (IS|IS NOT) enabled$")
        public void assertSeleniumIsEnabledByLocator​(String method,
                                                     String element,
                                                     Integer index,
                                                     String option)
        Verifies if a webelement referenced by locator is enabled or not
        
         Example:
        
          Scenario: Verify if element is enabled
               Given I go to 'https://demoqa.com/radio-button'
               And the element with 'id:yesRadio' IS enabled
               And the element with 'id:noRadio' index '0' IS NOT enabled
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        option - Whether the element is enabled or not
      • assertSeleniumIsSelectedByLocator

        @Then("^the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? (IS|IS NOT) selected$")
        public void assertSeleniumIsSelectedByLocator​(String method,
                                                      String element,
                                                      Integer index,
                                                      String option)
        Verifies if a webelement referenced by locator is selected or not
        
         Example:
        
          Scenario: Verify if an element is selected
               Given I go to 'https://demoqa.com/automation-practice-form'
               And the element with 'id:hobbies-checkbox-1' IS NOT selected
               When I click on the element with 'id:hobbies-checkbox-1' index '0'
               And the element with 'id:hobbies-checkbox-1' index '0' IS selected
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        option - the option (if it is enabled or not)
      • assertSeleniumHasAttributeValueByLocator

        @Then("^the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? has \'(.*?)\' as \'(.*)\'$")
        public void assertSeleniumHasAttributeValueByLocator​(String method,
                                                             String element,
                                                             Integer index,
                                                             String attribute,
                                                             String value)
        Verifies that a webelement referenced by locator has attribute with value (as a regexp)
        
         Example:
        
         Scenario: Verify the value of element's attribute
               Given I go to 'https://demoqa.com/text-box'
               Then the element with 'id:userName' has 'placeholder' as 'Full Name'
               Then the element with 'id:submit' index '0' has 'type' as 'button'
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        attribute - the attribute to verify
        value - 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:
        
         Scenario:
              Given I go to 'http:mydummysite/index.html'
              Then I take a snapshot
         
      • checkURL

        @Then("^we are in page \'(.*)\'$")
        public void checkURL​(String url)
        Checks that we are in the URL passed
        
         Example:
        
         Scenario: checking the current url
              Given I go to 'https://demoqa.com/'
              Then we are in page 'https://demoqa.com/'
         
        Parameters:
        url - the url to verify
        See Also:
        checkURLContains(String)
      • checkURLContains

        @Then("^the current url contains the text \'(.*)\'$")
        public void checkURLContains​(String text)
        Checks if the current URL contains the specified text.
        
         Example:
        
         Scenario: check if current url contains the word 'autocomplete'
              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
        See Also:
        checkURL(String)
      • saveSeleniumCookies

        @Then("^I save selenium cookies in context$")
        public void saveSeleniumCookies()
        Save cookie in context for future references
      • saveContentWebElementByLocatorInEnvVar

        @Then("^I save content of element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? in environment variable \'(.*)\'$")
        public void saveContentWebElementByLocatorInEnvVar​(String method,
                                                           String element,
                                                           Integer index,
                                                           String envVar)
        Takes the content of a webElement and stores it in the thread environment variable passed as parameter
        
         Example:
        
         Scenario: Saving the content of element
               Given I go to 'https://demoqa.com/text-box'
               When I save content of element with 'id:userName-label' in environment variable 'mytext'
               Then '${mytext}' matches 'Full Name'
         
        Parameters:
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        envVar - name of the thread environment variable where to store the text
        See Also:
        assertSeleniumNElementExists(String, 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 smethod
        source - initial web element
        dmethod - the dmethod
        destination - destination web element
      • seleniumClearByLocator

        @Then("^I clear the text of the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$")
        public void seleniumClearByLocator​(String method,
                                           String element,
                                           Integer index)
        Clear the text on the element referenced by locator.
        
         Example:
        
         Scenario: Clear the text on an element.
               Given I go to 'http://localhost/styled/basic-html-form-test.html'
               And I type 'John Smith' on the element with 'name:username'
               And I clear the text of the element with 'name:username'
               Then the element with 'name:username' has '' as text
         
        Parameters:
        index - index of the web element
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - locator of the element
        See Also:
        assertSeleniumNElementExists(String, Integer, String, String)
      • seleniumKeys

        @Deprecated
        @When("^I send \'(.*)\' on the element on index \'(\\d+)\'$")
        public void seleniumKeys​(String text,
                                 Integer index)
        Deprecated.
        Send a strokes list on an numbered url 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)
        waitWebElementWithPooling(int, int, int, String, String, String)

        
         Example:
        
         Scenario: Press enter on the given element
              Given I go to 'http:mydummysite/index.html'
              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 send
        index - index of the web element in the list
        See Also:
        seleniumType(String, Integer), assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String)
      • seleniumKeysByLocator

        @When("^I send \'(.*)\' on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$")
        public void seleniumKeysByLocator​(String input,
                                          String method,
                                          String element,
                                          Integer index)
        Send a strokes to an element referenced by locator.

        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 ( )

        
         Example:
        
         Scenario: Press enter on the given element
              Given I go to 'http:mydummysite/index.html'
              And I type 'testUser' on the element with 'id:name_3_firstname'
              Then I send 'ENTER' on the element with 'id:name_3_firstname'
         
        Parameters:
        input - key stroke to send
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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), assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String)
      • elementDeSelect

        @When("^I de-select every item on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?$")
        public void elementDeSelect​(String method,
                                    String element,
                                    Integer index)
        Choose no option from a select webelement found previously

        Parameters:
        index - index of the web element in the list
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
      • 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 open

        
         Example:
        
         Scenario:
              Given I go to 'http:mydummysite/index.html'
              Then I click on the element with 'name:pie_submit'
              Given a new window is opened
              Then I change active window
         
        See Also:
        seleniumGetwindows()
      • saveTheValueOfElementPropertyByLocator

        @Then("^I save the value of the property \'(.*)\' of the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? in variable \'(.*)\'$")
        public void saveTheValueOfElementPropertyByLocator​(String propertyName,
                                                           String method,
                                                           String element,
                                                           Integer index,
                                                           String variable)
        Saves the given property of the specified webelement (referenced by its locator) in the specified variable.
        
         Example:
        
         Scenario: Saving the value an attribute
               Given I go to 'https://demoqa.com/text-box'
               Then I save the value of the property 'type' of the element with 'id:submit' in variable 'TYPE'
               Then '${TYPE}' matches 'button'
         
        Parameters:
        propertyName - Name of the property of the HTML tag
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)
        variable - Variable where to save the result
        See Also:
        assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String)
      • executeJavascript

        @Then("^I execute \'(.*)\' as javascript( and save the result in the environment variable \'(.*)\')?$")
        public void executeJavascript​(String script,
                                      String enVar)
        Executes a JavaScript function in the current driver.
        
         Example:
        
          Scenario: Execute JavaScript functions
               Given I go to 'http:mydummysite/index.html'
               And I execute 'alert("This is an alert!")' as javascript
               And I check every '1' seconds for at least '5' seconds until an alert appears
               And I accept the alert
               And I execute 'return document.URL;' as javascript and save the result in the environment variable 'PAGE'
               And '${PAGE}' contains 'index.html'
        
         
        Parameters:
        script - Script to execute (i.e alert("This is an alert message"))
        enVar - If used, variable where to store the result of the execution of the script
        See Also:
        assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String), executeJavascript(String, String)
      • executeJavascriptOnElement

        @Then("^I execute \'(.*)\' as javascript on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')?( and save the result in the environment variable \'(.*)\')?$")
        public void executeJavascriptOnElement​(String script,
                                               String method,
                                               String element,
                                               Integer index,
                                               String enVar)
        Executes a JavaScript function in the given element referenced by locator
        
         Example:
        
          Scenario: Execute JavaScript functions
               Given I go to 'http:mydummysite/index.html'
               And I execute 'arguments[0].click();' as javascript on the element with 'xpath://*[@id="menu-item-158"]/a'
               And I execute 'alert("This is an alert!")' as javascript
        
         
        Parameters:
        script - Script to execute (i.e alert("This is an alert message"))
        method - Method to use to locate the web element (id, name, class, etc)
        element - The relative reference to the element
        index - If used, the index of the previously found web element on which to execute the function
        enVar - If used, variable where to store the result of the execution of the script
        See Also:
        assertSeleniumNElementExists(String, Integer, String, String), waitWebElementWithPooling(int, int, int, String, String, String), executeJavascript(String, String)
      • iGoToUrl

        @Given("^I go to \'(.*)\'$")
        public void iGoToUrl​(String url)
        Directly navigate to the specified url

        This 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 with seleniumBrowse(String, String)

        
         Examples:
        
         Scenario: Directly navigate to the given page
              Given I go to 'http://www.demoqa.com/autocomplete'
        
         Scenario: Setting a base path first
              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)
      • closeWindow

        @Given("^I close the current window$")
        public void closeWindow()
        Closes the current window
      • 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 locator

        This 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 as assertSeleniumNElementExists(String, Integer, String, String) 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)

        
         Examples:
        
         Scenario: Perform click on the element with id 'username'
              Given I go to 'http:mydummysite/index.html'
              When I click on the element with 'id:username'
        
         Scenario: Using index in case more than one element is found (first element has index 0)
              Given I go to 'http:mydummysite/index.html'
              When I click on the element with 'tagName:button' index '1'
         
        Parameters:
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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)
      • 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 as assertSeleniumNElementExists(String, 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)

        
         Examples:
        
         Scenario: Type 555-555 in the input field with id:phone_number
              Given I go to 'http:mydummysite/index.html'
              And I type '555-555' on the element with 'id:phone_number'
        
         Scenario: Using index in case more than one element is found (first element has index 0)
              Given I go to 'http:mydummysite/index.html'
              And I type '555-555' on the element with 'class:text-field' index '1'
         
         
        Parameters:
        input - text to type in the element
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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), seleniumTypeLongTextByLocator(String, String, Integer, DocString)
      • seleniumTypeLongTextByLocator

        @When("^I type on the element with \'(id|name|class|css|xpath|linkText|partialLinkText|tagName):(.*?)\'( index \'(\\d+)\')? the text:$")
        public void seleniumTypeLongTextByLocator​(String method,
                                                  String element,
                                                  Integer index,
                                                  io.cucumber.docstring.DocString input)
        Directly types the given large text in the element referenced by locator.

        This step types the given large string of text in the given element. It's very similar to seleniumTypeByLocator(String, String, String, Integer) but uses a DocString, which allows using large strings of text, suitable for typing a long address or a long comment. 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)

        
         Examples:
        
         Scenario: Typing a large piece of text
              Given I go to 'http:mydummysite/index.html'
              And I type on the element with 'id:message' the text:
               """
                Good morning George!
                ===============
                The package of your order with number 1234886 should be about to arrive!
               """
        
         Scenario: Using index in case more than one element is found (first element has index 0).
              Given I go to 'http:mydummysite/index.html'
              And I type on the element with 'id:message' index '0' the text:
               """
                Good morning ${USER_NAME}!
                ===============
                The package of your order with number ${ORDER_NUMBER} should be about to arrive!
               """
         
        Parameters:
        input - text to type in the element
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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), seleniumTypeByLocator(String, String, 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)
      • 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 visible

        This step executes a javascript function to automatically scroll the element into view.

        
         Example:
        
         Scenario: Scroll up and down the page until the referenced element is visible
              Given I go to 'http:mydummysite/index.html'
              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 downwards
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - The relative reference to the element
        index - 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
      • 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 locator

        This 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 as assertSeleniumNElementExists(String, Integer, String, String) 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:
        
         Scenario: Perform double click on the element with id 'doubleClickBtn'
              Given I go to 'http:mydummysite/index.html'
              When I double click on the element with 'id:doubleClickBtn'
        
         Scenario: Using index in case more than one element is found (first element has index 0)
              Given I go to 'http:mydummysite/index.html'
              When I double click on the element with 'tagName:button' index '1'
         
        Parameters:
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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)
      • 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 locator

        This 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 as assertSeleniumNElementExists(String, Integer, String, String) 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:
        
         Scenario: Perform right click on the element with id 'rightClickBtn'
              Given I go to 'http:mydummysite/index.html'
              When I right click on the element with 'id:rightClickBtn'
        
         Scenario: Using index in case more than one element is found (first element has index 0)
              Given I go to 'http:mydummysite/index.html'
              When I right click on the element with 'tagName:button' index '1'
         
         
        Parameters:
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - 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)
      • 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 locator

        This 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:
        
         Scenario: Hover on element
              Given I go to 'http:mydummysite/index.html'
              Given I hover on the element with 'id:revelPopUpButton'
        
         Scenario: Using index in case more than one element is found (first element has index 0)
              Given I go to 'http:mydummysite/index.html'
              Given I hover on the element with 'id:revelPopUpButton' index '1'
         
        Parameters:
        method - method to locate the elements (id, name, class, css, xpath, linkText, partialLinkText and tagName)
        element - the relative reference to the element
        index - Index of the element, in case one or more elements with the given locator are found (first element starts with index 0)