Class CommonG


  • public class CommonG
    extends Object
    Class with common functions used by all the step definition classes
    • Constructor Detail

      • CommonG

        public CommonG()
    • Method Detail

      • getSeleniumAlert

        public org.openqa.selenium.Alert getSeleniumAlert()
      • setSeleniumAlert

        public void setSeleniumAlert​(org.openqa.selenium.Alert seleniumAlert)
      • getRestProtocol

        public String getRestProtocol()
      • setRestProtocol

        public void setRestProtocol​(String restProtocol)
        Set the REST host.
        Parameters:
        restProtocol - api protocol "http or https"
      • getCookies

        public List<com.ning.http.client.cookie.Cookie> getCookies()
      • setCookies

        public void setCookies​(List<com.ning.http.client.cookie.Cookie> cookies)
      • getSeleniumCookies

        public Set<org.openqa.selenium.Cookie> getSeleniumCookies()
      • setSeleniumCookies

        public void setSeleniumCookies​(Set<org.openqa.selenium.Cookie> cookies)
      • matchesOrContains

        public static Pattern matchesOrContains​(String expectedMessage)
        Checks if a given string matches a regular expression or contains a string
        Parameters:
        expectedMessage - message used for comparing
        Returns:
        boolean
      • getLastFileParseRecord

        public Map<String,​String> getLastFileParseRecord()
        Returns the last selected record
        Returns:
        record in the set
      • setLastFileParseRecord

        public void setLastFileParseRecord​(Map<String,​String> lastFileParseRecord)
        Sets the record for the last operation
        Parameters:
        lastFileParseRecord - record in the set
      • getLastSoapResponse

        public String getLastSoapResponse()
        Returns the las response from a remote method execution in the webservice as an XML String
        Returns:
        XML String
      • setLastSoapResponse

        public void setLastSoapResponse​(String lastSoapResponse)
        Sets the response of the execution of a remote method in a webservice as an XML String
        Parameters:
        lastSoapResponse - SOAP response of last operation
      • getLastFileParseResult

        public List<Map<String,​String>> getLastFileParseResult()
        Returns the records resulted from the last operation when decoding/parsing files
        Returns:
        records from last operation
      • setLastFileParseResult

        public void setLastFileParseResult​(List<Map<String,​String>> lastFileParseResult)
        Stores the result of an operation when decoding/parsing files
        Parameters:
        lastFileParseResult - records as result of last operation
      • getRestCookies

        public Map<String,​String> getRestCookies()
        Set the values of the cookies used when performing rest requests
        Returns:
        get the cookies returned from last operation
      • setRestCookies

        public void setRestCookies​(Map<String,​String> restCookies)
        Returns the values of the cookies used in the rest requests
        Parameters:
        restCookies - Set REST cookies from last operation
      • getRestResponse

        public io.restassured.response.Response getRestResponse()
        Get the previos Rest response (restassured)
        Returns:
        Rest response
      • setRestResponse

        public void setRestResponse​(io.restassured.response.Response restResponse)
        Sets the Rest response (restassured)
        Parameters:
        restResponse - Rest response
      • getRestRequest

        public io.restassured.specification.RequestSpecification getRestRequest()
        Returns the Rest Request object (restassured)
        Returns:
        Rest Request object (restassured)
      • setRestRequest

        public void setRestRequest​(io.restassured.specification.RequestSpecification restRequest)
        Sets the Rest request object (restassured)
        Parameters:
        restRequest - Rest Request object (restassured)
      • getPreviousSqlResult

        public List<List<String>> getPreviousSqlResult()
        Get the SQL result from the last step
        Returns:
        SQL result
      • setPreviousSqlResult

        public void setPreviousSqlResult​(List<List<String>> previousSqlResult)
        Sets the result of the SQL sentence
        Parameters:
        previousSqlResult - SQL result
      • getRemoteSSHConnection

        public RemoteSSHConnection getRemoteSSHConnection()
        Get the common remote connection.
        Returns:
        RemoteConnection
      • setRemoteSSHConnection

        public void setRemoteSSHConnection​(RemoteSSHConnection remoteSSHConnection)
        Set the remote connection.
        Parameters:
        remoteSSHConnection - remoteSSHConnection connection object
      • getRestHost

        public String getRestHost()
        Get the common REST host.
        Returns:
        REST host
      • setRestHost

        public void setRestHost​(String restHost)
        Set the REST host.
        Parameters:
        restHost - api host
      • getRestPort

        public String getRestPort()
        Get the common REST port.
        Returns:
        String
      • setRestPort

        public void setRestPort​(String restPort)
        Set the REST port.
        Parameters:
        restPort - api port
      • getWebHost

        public String getWebHost()
        Get the common WEB host.
        Returns:
        String
      • setWebHost

        public void setWebHost​(String webHost)
        Set the WEB host.
        Parameters:
        webHost - host where app is running
      • getWebPort

        public String getWebPort()
        Get the common WEB port.
        Returns:
        String
      • setWebPort

        public void setWebPort​(String webPort)
        Set the WEB port.
        Parameters:
        webPort - port where app is running
      • getLogger

        public org.slf4j.Logger getLogger()
        Get the common logger.
        Returns:
        Logger
      • getExceptions

        public List<Exception> getExceptions()
        Get the exception list.
        Returns:
        List(Exception)
      • getTextFieldCondition

        public org.assertj.core.api.Condition<org.openqa.selenium.WebElement> getTextFieldCondition()
        Get the textFieldCondition list.
        Returns:
        List(Exception)
      • getCassandraClient

        public CassandraUtils getCassandraClient()
        Get the cassandra utils.
        Returns:
        CassandraUtils
      • getElasticSearchClient

        public ElasticSearchUtils getElasticSearchClient()
        Get the elasticSearch utils.
        Returns:
        ElasticSearchUtils
      • getKafkaUtils

        public KafkaUtils getKafkaUtils()
        Get the Kafka utils.
        Returns:
        KafkaUtils
      • getMongoDBClient

        public MongoDBUtils getMongoDBClient()
        Get the MongoDB utils.
        Returns:
        MongoDBUtils
      • getSqlClient

        public SqlUtils getSqlClient()
        Get the SQL utils.
        Returns:
        SqlUtils
      • getSoapServiceClient

        public SoapServiceUtils getSoapServiceClient()
        Get the SOAP Services utils.
        Returns:
        SoapServiceUtils
      • getFileParserUtil

        public FileParserUtils getFileParserUtil()
        Get the File Parser class
        Returns:
        FileParserUtils
      • getZookeeperSecClient

        public ZookeeperSecUtils getZookeeperSecClient()
        Get the Zookeeper Sec utils.
        Returns:
        ZookeperSecUtils
      • getDriver

        public org.openqa.selenium.WebDriver getDriver()
        Get the remoteWebDriver.
        Returns:
        RemoteWebDriver
      • setDriver

        public void setDriver​(org.openqa.selenium.WebDriver driver)
        Set the remoteDriver.
        Parameters:
        driver - driver to be used for testing
      • getBrowserName

        public String getBrowserName()
        Get the browser name.
        Returns:
        String
      • setBrowserName

        public void setBrowserName​(String browserName)
        Set the browser name.
        Parameters:
        browserName - browser to be used for testing
      • locateElement

        public List<org.openqa.selenium.WebElement> locateElement​(String method,
                                                                  String element,
                                                                  Integer expectedCount)
        Looks for webelements inside a selenium context. This search will be made by id, name and xpath expression matching an locator value
        Parameters:
        method - class of element to be searched
        element - webElement searched in selenium context
        expectedCount - integer. Expected number of elements.
        Returns:
        List(WebElement)
      • locateElementWithPooling

        public List<org.openqa.selenium.WebElement> locateElementWithPooling​(int poolingInterval,
                                                                             int poolMaxTime,
                                                                             String method,
                                                                             String element,
                                                                             Integer expectedCount,
                                                                             String type)
        Similar to locateElement(String, String, Integer). Looks for webelements inside a selenium context but with a wait condition. Instead of returning immediately a fail if the element is not found, the method waits a maximum time (poolMaxTime) in which the condition is checked in intervals (poolingInterval). The method also verify if the required elements are of the type specified.
        Parameters:
        poolingInterval - Time between consecutive condition evaluations
        poolMaxTime - Maximum time to wait for the condition to be true
        method - class of element to be searched
        element - webElement searched in selenium context
        expectedCount - integer. Expected number of elements.
        type - The expected style of the element: visible, clickable, present, hidden
        Returns:
        List(WebElement)
      • waitAlertWithPooling

        public org.openqa.selenium.Alert waitAlertWithPooling​(int poolingInterval,
                                                              int poolMaxTime)
        Similar to locateElementWithPooling(int, int, String, String, Integer, String), looks for an alert message inside a selenium context. The method waits a maximum time (poolMaxTime) in which the condition is checked in intervals (poolingInterval).
        Parameters:
        poolingInterval - Time between consecutive condition evaluations
        poolMaxTime - Maximum time to wait for the condition to be true
        Returns:
        A selenium Alert object
      • dismissSeleniumAlert

        public void dismissSeleniumAlert()
        Dismiss any existing alert message in the current selenium context
      • acceptSeleniumAlert

        public void acceptSeleniumAlert()
        Accepts any existing alert message in the current selenium context
      • captureEvidence

        public String captureEvidence​(org.openqa.selenium.WebDriver driver,
                                      String type)
        Capture a snapshot or an evidence in the driver
        Parameters:
        driver - driver used for testing
        type - type
        Returns:
        String
      • captureEvidence

        public String captureEvidence​(org.openqa.selenium.WebDriver driver,
                                      String type,
                                      String suffix)
        Capture a snapshot or an evidence in the driver
        Parameters:
        driver - driver used for testing
        type - type
        suffix - suffix
        Returns:
        String
      • getPreviousWebElements

        public PreviousWebElements getPreviousWebElements()
        Returns the previous webElement
        Returns:
        List(WebElement)
      • setPreviousWebElements

        public void setPreviousWebElements​(PreviousWebElements previousWebElements)
        Set the previous webElement
        Parameters:
        previousWebElements - webElement
      • getParentWindow

        public String getParentWindow()
        Returns the parentWindow
        Returns:
        String
      • setParentWindow

        public void setParentWindow​(String windowHandle)
        Sets the parentWindow
        Parameters:
        windowHandle - windowHandle as string
      • getClient

        public com.ning.http.client.AsyncHttpClient getClient()
      • setClient

        public void setClient​(com.ning.http.client.AsyncHttpClient client)
      • setResponse

        public void setResponse​(String endpoint,
                                com.ning.http.client.Response response)
                         throws IOException
        Throws:
        IOException
      • retrieveData

        public String retrieveData​(String baseData,
                                   String type)
        Returns the information contained in file passed as parameter. the file is read with UTF-8 charset by default
        Parameters:
        baseData - path to file to be read
        type - type of information, it can be: json|string
        Returns:
        String
      • retrieveData

        public String retrieveData​(String baseData,
                                   String type,
                                   String charset)
        Returns the information contained in file passed as parameter
        Parameters:
        baseData - path to file to be read
        type - type of information, it can be: json|string
        charset - charset to use when reading the file
        Returns:
        String
      • modifyData

        public String modifyData​(String data,
                                 String type,
                                 io.cucumber.datatable.DataTable modifications)
                          throws Exception
        Returns the information modified
        Parameters:
        data - string containing the information
        type - type of information, it can be: json|string
        modifications - modifications to apply with a format: WHERE,ACTION,VALUE

        DELETE: Delete the key in json or string in current value in case of DELETE action modifications is |key1|DELETE|N/A| and with json {"key1":"value1","key2":{"key3":null}} returns {"key2":{"key3":null}} Example 2: {"key1":"val1", "key2":"val2"} -> | key1 | DELETE | N/A | -> {"key2":"val2"} "mystring" -> | str | DELETE | N/A | -> "mying"

        ADD: Add new key to json or append string to current value. in case of ADD action is |N/A|ADD|&config=config|, and with data username=username&password=password returns username=username&password=password&config=config Example 2: {"key1":"val1", "key2":"val2"} -> | key3 | ADD | val3 | -> {"key1":"val1", "key2":"val2", "key3":"val3"} "mystring" -> | N/A | ADD | new | -> "mystringnew"

        UPDATE: Update value in key or modify part of string. in case of UPDATE action is |username=username|UPDATE|username=NEWusername|, and with data username=username&password=password returns username=NEWusername&password=password Example 2: {"key1":"val1", "key2":"val2"} -> | key1 | UPDATE | newval1 | -> {"key1":"newval1", "key2":"val2"} "mystring" -> | str | UPDATE | mod | -> "mymoding"

        PREPEND: Prepend value to key value or to string in case of PREPEND action is |username=username|PREPEND|key1=value1&|, and with data username=username&password=password returns key1=value1&username=username&password=password Example 2: {"key1":"val1", "key2":"val2"} -> | key1 | PREPEND | new | -> {"key1":"newval1", "key2":"val2"} "mystring" -> | N/A | PREPEND | new | -> "newmystring"

        REPLACE: Update value in key or modify part of string. in case of REPLACE action is |key2.key3|REPLACE|lu->REPLACE| and with json {"key1":"value1","key2":{"key3":"value3"}} returns {"key1":"value1","key2":{"key3":"vaREPLACEe3"}} the format is (WHERE, ACTION, CHANGE FROM -> TO). REPLACE replaces a string or its part per other string

        if modifications has fourth argument, the replacement is effected per special json object the format is: (WHERE, ACTION, CHANGE_TO, JSON_TYPE), WHERE is the key, ACTION is REPLACE, CHANGE_TO is the new value of the key, JSON_TYPE is the type of jason object, there are 5 special cases of json object replacements: array|object|number|boolean|null

        example1: |key2.key3|REPLACE|5|number| with json {"key1":"value1","key2":{"key3":"value3"}} returns {"key1":"value1","key2":{"key3":5}} in this case it replaces value of key3 per jason number

        example2: |key2.key3|REPLACE|{}|object| with json {"key1":"value1","key2":{"key3":"value3"}} returns {"key1":"value1","key2":{"key3":{}}} in this case it replaces per empty json object

        APPEND: Append value to key value or to string {"key1":"val1", "key2":"val2"} -> | key1 | APPEND | new | -> {"key1":"val1new", "key2":"val2"} "mystring" -> | N/A | APPEND | new | -> "mystringnew"

        Returns:
        String
        Throws:
        Exception - Exception
      • generateRequest

        @Deprecated
        public Future<com.ning.http.client.Response> generateRequest​(String requestType,
                                                                     boolean secure,
                                                                     String user,
                                                                     String password,
                                                                     String endPoint,
                                                                     String data,
                                                                     String type,
                                                                     String codeBase64)
                                                              throws Exception
        Deprecated.
        Generates the request based on the type of request, the end point, the data and type passed
        Parameters:
        requestType - type of request to be sent
        secure - type of protocol
        user - user to be used in request
        password - password to be used in request
        endPoint - end point to sent the request to
        data - to be sent for PUT/POST requests
        type - type of data to be sent (json|string)
        codeBase64 - XXX
        Returns:
        request object
        Throws:
        Exception - exception
      • generateRequest

        public Future<com.ning.http.client.Response> generateRequest​(String requestType,
                                                                     boolean secure,
                                                                     String user,
                                                                     String password,
                                                                     String endPoint,
                                                                     String data,
                                                                     String type)
                                                              throws Exception
        Generates the request based on the type of request, the end point, the data and type passed
        Parameters:
        requestType - type of request to be sent
        secure - type of protocol
        user - user to be used in request
        password - password to be used in request
        endPoint - end point to sent the request to
        data - to be sent for PUT/POST requests
        type - type of data to be sent (json|string)
        Returns:
        rest request
        Throws:
        Exception - exception
      • generateRequest

        @Deprecated
        public Future<com.ning.http.client.Response> generateRequest​(String requestType,
                                                                     boolean secure,
                                                                     String endPoint,
                                                                     String data,
                                                                     String type,
                                                                     String codeBase64)
                                                              throws Exception
        Deprecated.
        Generates the request based on the type of request, the end point, the data and type passed
        Parameters:
        requestType - type of request to be sent
        secure - type of protocol
        endPoint - end point to sent the request to
        data - to be sent for PUT/POST requests
        type - type of data to be sent (json|string)
        codeBase64 - codeBase64
        Returns:
        rest request
        Throws:
        Exception - exception
      • generateRestRequest

        public void generateRestRequest​(String requestType,
                                        String endPoint)
        Generates a request to a REST endpoint
        Parameters:
        requestType - Request type (GET, POST, PUT, DELETE, PATCH)
        endPoint - Final endpoint (i.e /user/1)
      • getCassandraResults

        public com.datastax.driver.core.ResultSet getCassandraResults()
      • setCassandraResults

        public void setCassandraResults​(com.datastax.driver.core.ResultSet results)
      • getMongoResults

        public com.mongodb.DBCursor getMongoResults()
      • setMongoResults

        public void setMongoResults​(com.mongodb.DBCursor results)
      • getElasticsearchResults

        public List<org.json.JSONObject> getElasticsearchResults()
      • setElasticsearchResults

        public void setElasticsearchResults​(List<org.json.JSONObject> results)
      • getResultsType

        public String getResultsType()
      • setResultsType

        public void setResultsType​(String resultsType)
      • resultsMustBeCSV

        public void resultsMustBeCSV​(io.cucumber.datatable.DataTable expectedResults)
                              throws Exception
        Checks the different results of a previous query to CSV file
        Parameters:
        expectedResults - A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns: a) A field column from the result b) Occurrences column (Integer type)

        Example: |latitude| longitude|place |occurrences| |12.5 |12.7 |Valencia |1 | |2.5 | 2.6 |Madrid |0 | |12.5 |13.7 |Sevilla |1 | IMPORTANT: All columns must exist

        Throws:
        Exception - exception
      • resultsMustBeCassandra

        public void resultsMustBeCassandra​(io.cucumber.datatable.DataTable expectedResults)
                                    throws Exception
        Checks the different results of a previous query to Cassandra database
        Parameters:
        expectedResults - A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns: a) A field column from the result b) Occurrences column (Integer type)

        Example: |latitude| longitude|place |occurrences| |12.5 |12.7 |Valencia |1 | |2.5 | 2.6 |Madrid |0 | |12.5 |13.7 |Sevilla |1 | IMPORTANT: All columns must exist

        Throws:
        Exception - exception
      • resultsMustBeMongo

        public void resultsMustBeMongo​(io.cucumber.datatable.DataTable expectedResults)
                                throws Exception
        Checks the different results of a previous query to Mongo database
        Parameters:
        expectedResults - A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns: a) A field column from the result b) Occurrences column (Integer type)

        Example: |latitude| longitude|place |occurrences| |12.5 |12.7 |Valencia |1 | |2.5 | 2.6 |Madrid |0 | |12.5 |13.7 |Sevilla |1 | IMPORTANT: All columns must exist

        Throws:
        Exception - exception
      • resultsMustBeElasticsearch

        public void resultsMustBeElasticsearch​(io.cucumber.datatable.DataTable expectedResults)
                                        throws Exception
        Checks the different results of a previous query to Elasticsearch database
        Parameters:
        expectedResults - A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns: a) A field column from the result b) Occurrences column (Integer type)

        Example: |latitude| longitude|place |occurrences| |12.5 |12.7 |Valencia |1 | |2.5 | 2.6 |Madrid |0 | |12.5 |13.7 |Sevilla |1 | IMPORTANT: All columns must exist

        Throws:
        Exception - exception
      • runLocalCommand

        public void runLocalCommand​(String command)
                             throws Exception
        Runs a command locally
        Parameters:
        command - Command used to be run locally
        Throws:
        Exception - Exception
      • getCommandExitStatus

        public int getCommandExitStatus()
      • setCommandExitStatus

        public void setCommandExitStatus​(int commandExitStatus)
      • getCommandResult

        public String getCommandResult()
      • setCommandResult

        public void setCommandResult​(String commandResult)
      • getJSONPathString

        public String getJSONPathString​(String jsonString,
                                        String expr,
                                        String position)
        Parse jsonpath expression from a given string.

        If the string is json we can obtain its keys using ~ symbol.

        If position is not null and the result of jsonpath expression is an array, then this function will return the element at the given position at the array.

        If position is null, it will return the result of the jsonpath evaluation as string.

        Parameters:
        jsonString - string to be parsed
        expr - jsonpath expression
        position - position from a search result
        Returns:
        the resulting element as string
      • removeJSONPathElement

        public String removeJSONPathElement​(String jsonString,
                                            String expr)
        Remove a subelement in a JsonPath
        Parameters:
        jsonString - String of the json
        expr - regex to be removed
        Returns:
        new json
      • replaceJSONPathElement

        public String replaceJSONPathElement​(String jsonString,
                                             String key,
                                             String value)
        The function searches over the array by certain field value, and replaces occurences with the parameter provided.
        Parameters:
        jsonString - Original json object
        key - Key to search
        value - Value to replace key with
        Returns:
        new json
      • evaluateJSONElementOperation

        public void evaluateJSONElementOperation​(Object o,
                                                 String condition,
                                                 String result)
        Evaluate an expression.

        Object o could be a string or a list.

        Parameters:
        o - object to be evaluated
        condition - condition to compare
        result - expected result
      • updateMarathonJson

        public String updateMarathonJson​(String json)
      • runCommandLoggerAndEnvVar

        public void runCommandLoggerAndEnvVar​(int exitStatus,
                                              String envVar,
                                              Boolean local)
      • addSsoToken

        public List<com.ning.http.client.cookie.Cookie> addSsoToken​(HashMap<String,​String> ssoCookies,
                                                                    String[] tokenList)
        Add sso token list.
        Parameters:
        ssoCookies - the sso cookies
        tokenList - the token list
        Returns:
        the list
      • getVariable

        public String getVariable​(String variable)
        Returns the value of the given placeholder as used in the gherkin step
         Examples:
         
              getVariable("${variable}")      //returns the java property
              getVariable("!{variable}")      //returns the thread property
              getVariable("#{variable}")      //returns the corresponding value from the properties file.
              getVariable("@{variable}")      //returns attribute value
         
         
        Parameters:
        variable - Variable placeholder as used in the gherkin file
        Returns:
        Value assign to that variable
        See Also:
        ReplacementAspect.replacedElement(String, JoinPoint)