Class SeleniumRemoteHelper


  • public final class SeleniumRemoteHelper
    extends Object
    This class contains several functions to extract information from a remote Selenium grid/standalone node
    Author:
    José Fernández
    • Constructor Detail

      • SeleniumRemoteHelper

        public SeleniumRemoteHelper()
    • Method Detail

      • getNodeSessions

        public String getNodeSessions()
      • getPageSource

        public String getPageSource()
      • connectToGrid

        public SeleniumRemoteHelper connectToGrid​(String gridBaseUrl)
        Connects to the grid to the given ip:port (i.e localhost:4444)
        Parameters:
        gridBaseUrl - grid ip:port
        Returns:
        this object to allow chaining
      • getAllAvailableNodesFromGrid

        @Deprecated
        public List<String> getAllAvailableNodesFromGrid()
                                                  throws com.fasterxml.jackson.core.JsonProcessingException
        Deprecated.
        This method may not work with newer version of selenium grid since the UI has changed completely!
        Returns the list of the nodes that are available (not busy). Each node in the list if represented by a json string with the capabilities of the node
        Returns:
        List of free nodes
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - the json processing exception
      • getAllNodesFromGrid

        public List<String> getAllNodesFromGrid()
                                         throws com.fasterxml.jackson.core.JsonProcessingException
        Returns the list of all the nodes (regardless if they are busy or not). Each node in the list if represented by a json string with the capabilities of the node
        Returns:
        List of all nodes
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - the json processing exception
      • filterNodes

        public List<String> filterNodes​(List<String> availableNodes,
                                        Map<String,​String> filter)
        Apply the given filter to the list of nodes and only returns the nodes that matches the given filter. The filter contains key-value pairs, where the key is the name of one particular capability and the value the capability value. For example, the filter browserName=firefox, will return from the given list of nodes the ones where browserName has value firefox in the list of capabilities
        Parameters:
        availableNodes - List of nodes
        filter - Filter to apply
        Returns:
        nodes that match the filter
      • transformToJsonString

        public String transformToJsonString​(String node)
                                     throws com.fasterxml.jackson.core.JsonProcessingException
        Transforms the string representation of the node's capabilities into a proper json string
        Parameters:
        node - Capabilities string
        Returns:
        Capabilities string with proper json string format
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - the json processing exception
      • connectToStandAloneNode

        public SeleniumRemoteHelper connectToStandAloneNode​(String standAloneNode)
                                                     throws IOException
        Verifies the Standalone node is in the address specified and get the list of sessions
        Parameters:
        standAloneNode - Address as ip:port (i.e: localhost:4444)
        Returns:
        This to allow chaining
        Throws:
        IOException - IOException
      • getAllSessions

        public List<String> getAllSessions()
                                    throws IOException
        Gets the fetch list of sessions and returns them as list of capabilities
        Returns:
        list of sessions capabilities
        Throws:
        IOException - IOException