Class AbstractTestBenchTest

  • All Implemented Interfaces:
    com.vaadin.testbench.HasDriver, com.vaadin.testbench.HasElementQuery, com.vaadin.testbench.HasSearchContext, com.vaadin.testbench.HasTestBenchCommandExecutor
    Direct Known Subclasses:
    ViewOrUITest

    public abstract class AbstractTestBenchTest
    extends TestBenchHelpers
    Abstract base class for flow TestBench tests.
    Since:
    1.0
    • Field Detail

      • SERVER_PORT_PROPERTY_KEY

        public static final String SERVER_PORT_PROPERTY_KEY
        System property key for the test server port.
        See Also:
        Constant Field Values
      • SERVER_PORT

        public static final int SERVER_PORT
        Server port resolved by system property "serverPort" or the default "8888".
      • USE_HUB

        public static final boolean USE_HUB
      • USE_BROWSERSTACK

        public static final boolean USE_BROWSERSTACK
      • BROWSERSTACK_IDENTIFIER

        public static final String BROWSERSTACK_IDENTIFIER
      • testName

        public org.junit.rules.TestName testName
    • Constructor Detail

      • AbstractTestBenchTest

        public AbstractTestBenchTest()
    • Method Detail

      • checkIfServerAvailable

        public void checkIfServerAvailable()
        Checks that server is available before running the actual test.
      • open

        protected void open()
      • open

        protected void open​(String... parameters)
      • openProduction

        protected void openProduction​(String... parameters)
      • openProductionWithTiming

        protected void openProductionWithTiming​(String... parameters)
      • openForEs6Url

        protected void openForEs6Url​(String... parameters)
      • openUrl

        protected void openUrl​(String targetUrl,
                               String... parameters)
      • isClientRouter

        protected final boolean isClientRouter()
        Returns true when using clientSide routing
        Returns:
        true when client-side route
      • waitForClientRouter

        protected void waitForClientRouter()
        Waits until clientSide route renders the view.
      • getTestURL

        protected String getTestURL​(String... parameters)
        Returns the URL to be used for the test.
        Parameters:
        parameters - query string parameters to add to the url
        Returns:
        the URL for the test
      • getTestPath

        protected abstract String getTestPath()
        Gets the absolute path to the test, starting with a "/".
        Returns:
        the path to the test, appended to getRootURL() for the full test URL.
      • getRootURL

        protected String getRootURL()
        Returns the URL to the root of the server, e.g. "http://localhost:8888"
        Returns:
        the URL to the root
      • verifyScreenshot

        protected void verifyScreenshot​(String identifier)
                                 throws IOException
        Compares the given reference screenshot to the current and fails the test if it doesn't match.
        Parameters:
        identifier - the identifier to use for the screenshot, becomes part of the screenshot name in the module-folder/reference-screenshots/ folder
        Throws:
        IOException - if there was a problem accessing the reference image
      • getBrowsersToTest

        public List<org.openqa.selenium.remote.DesiredCapabilities> getBrowsersToTest()
        Produces a collection of browsers to run the test on. This method is executed by the test runner when determining how many test methods to invoke and with what parameters. For each returned value a test method is ran and before running that, ParallelTest.setDesiredCapabilities(DesiredCapabilities) is invoked with the value returned by this method.
        Returns:
        The browsers to run the test on
      • getHubBrowsersToTest

        protected List<org.openqa.selenium.remote.DesiredCapabilities> getHubBrowsersToTest()
        Gets the browsers capabilities list to execute test on the tests Hub.

        This list will be used only for the tests Hub. Local test execution is managed by LocalExecution annotation.

        The method getBrowsersToTest() delegates the logic to this method in case getLocalExecution() return value is an empty optional (i.e. the tests Hub is used).

        Returns:
        the browsers capabilities list to execute test on the tests Hub
      • getBrowserCapabilities

        protected List<org.openqa.selenium.remote.DesiredCapabilities> getBrowserCapabilities​(com.vaadin.testbench.parallel.Browser... browsers)
        Gets browser capabilities for the provided browsers.
        Parameters:
        browsers - a browsers list
        Returns:
        the capabilities for the given browsers
      • getDeploymentHostname

        protected String getDeploymentHostname()
        Used to determine what URL to initially open for the test.
        Returns:
        the host name of development server
      • getCurrentHostAddress

        protected String getCurrentHostAddress()
        Returns host address that can be targeted from the outside, like from a test hub.
        Returns:
        host address
        Throws:
        RuntimeException - if host name could not be determined or SocketException was caught during the determination.
      • getDeploymentPort

        protected int getDeploymentPort()
        Used to determine what port the test is running on.
        Returns:
        The port the test is running on, by default AbstractTestBenchTest.DEFAULT_SERVER_PORT
      • getHubHostname

        protected String getHubHostname()
        Overrides:
        getHubHostname in class com.vaadin.testbench.parallel.ParallelTest
      • getRunLocallyBrowser

        protected com.vaadin.testbench.parallel.Browser getRunLocallyBrowser()
        Overrides:
        getRunLocallyBrowser in class com.vaadin.testbench.parallel.ParallelTest
      • getRunLocallyBrowserVersion

        protected String getRunLocallyBrowserVersion()
        Overrides:
        getRunLocallyBrowserVersion in class com.vaadin.testbench.parallel.ParallelTest
      • getLocalExecution

        protected Optional<LocalExecution> getLocalExecution()
        Gets local execution (LocalExecution) configuration for the test.

        If this method return an empty optional then test with be run on the test Hub

        Returns:
        an optional configuration, or an empty optional if configuration is disabled or not available
        See Also:
        LocalExecution
      • getTestURL

        public static String getTestURL​(String rootUrl,
                                        String testPath,
                                        String... parameters)
        Returns the URL to be used for the test.
        Parameters:
        parameters - query string parameters to add to the url
        rootUrl - the root URL of the server (hostname + port)
        testPath - the path of the test
        Returns:
        the URL for the test