Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

embedded-selenium

Maven dependency

pom.xml
<dependency>
    <groupId>com.playtika.testcontainers</groupId>
    <artifactId>embedded-selenium</artifactId>
    <scope>test</scope>
</dependency>

Consumes (via bootstrap.properties)

  • embedded.selenium.enabled (true|false, default is true)

  • embedded.selenium.browser (enum, FIREFOX|CHROMIUM, default is 'CHROMIUM')

  • embedded.selenium.docker-image (Docker image like "selenium/standalone-chrome-debug:3.141.59")

    • Image versions on dockerhub repositories

    • Prefix "standalone-" has a browser installed, suffix "-debug" additionally a VNC server for docker-selenium

  • embedded.selenium.vnc.mode RECORD_ALL | SKIP | RECORD_FAILING

  • embedded.selenium.vnc.recording-dir a file location

  • embedded.toxiproxy.proxies.selenium.enabled Enables both creation of the container with ToxiProxy TCP proxy and a proxy to the embedded-selenium container.

Produces

  • embedded.selenium.port

  • embedded.selenium.host

  • embedded.selenium.vnc.host

  • embedded.selenium.vnc.port (mapped HTTP port)

  • embedded.selenium.vnc.username

  • embedded.selenium.vnc.password

  • embedded.selenium.toxiproxy.host

  • embedded.selenium.toxiproxy.port

  • embedded.selenium.networkAlias

  • Bean ToxiproxyClientProxy seleniumContainerProxy

Example

There is currently no starter library for using selenium server so there is no need to use the produced variables. You can control the configuration of the browser in 2 ways. The first is via the properties file:

/src/test/resources/application.yaml
embedded:
  selenium:
    enabled: true
    browser: CHROMIUM
    arguments:
        - ignore-certificate-errors

The second (which may be more configurable) is via defining either a ChromeOptions class or a FirefoxOptions class in your test class:

    @TestConfiguration
    static class LocalTestConfiguration {

        @Bean
        public FirefoxOptions firefoxOptions(SeleniumProperties properties) {

            FirefoxOptions options = new FirefoxOptions();
            properties.apply(options);
            options.addArguments("hello-world");
            options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, false);
            options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, false);
            return options;
        }
    }

If you are testing your local machine you can access the hostname via the annotation

    @DockerHostname
    private String hostname;

An example test class would look like the following:

import org.openqa.selenium.WebDriver;@RunWith(SpringRunner.class)
@SpringBootTest(
        classes = SpringBootWebApplication.class,
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
@Import(TestLoginPage.LocalTestConfiguration.class)
public class TestLoginPage {

    @LocalServerPort
    private int port;

    @DockerHostname
    private String hostname;

    @Autowired
    private BrowserWebDriverContainer webDriverContainer;

    @Test
    public void test1() {
        RemoteWebDriver webDriver = webDriverContainer.getWebDriver();
        webDriver.get("https://" + hostname +":" + port);
        assertThat(webDriver.getPageSource()).contains("helloworld");
    }

    @TestConfiguration
    static class LocalTestConfiguration {

        @Bean
        public FirefoxOptions firefoxOptions(SeleniumProperties properties) {

            FirefoxOptions options = new FirefoxOptions();
            properties.apply(options);
            options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
            return options;
        }
    }
}