qaf icon indicating copy to clipboard operation
qaf copied to clipboard

How can I use WebDriverManager in Docker?

Open nshthshah opened this issue 2 years ago • 2 comments

QAF Version

3.1.0

Expected behavior

It should support WDM with Docker with the latest version of WDM. Reference: https://bonigarcia.dev/webdrivermanager/

nshthshah avatar Mar 12 '22 03:03 nshthshah

The provided information is not enough to understand problem. However, for custom implementation, below are the steps you can follow:

  • Disable default behavior by setting manage.driver.executable=false
  • Use driver listener to setup driver manager. Refer example form https://github.com/qmetry/qaf/issues/370#issuecomment-891169671 and driver listener

cjayswal avatar Mar 18 '22 19:03 cjayswal

WebDriverManager 5 is the ability to create browsers in Docker containers out of the box. The requirement to use this feature is to have installed a Docker Engine in the machine running the tests. To use it, we need to invoke the method browserInDocker() in conjunction with create() of a given manager. This way, WebDriverManager pulls the image from Docker Hub, starts the container, and instantiates the WebDriver object to use it. The following test shows a simple example using Chrome in Docker:

WebDriver driver;
WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker();

@BeforeEach
    void setupTest() {
        driver = wdm.create();
    }

    @AfterEach
    void teardown() {
        wdm.quit();
    }

Reference Link: https://bonigarcia.dev/webdrivermanager/#browsers-in-docker

Currently, there are two commands need to be executed, docker run -d -p 4444:4444 --shm-size="2g" selenium/standalone-chrome:93.0

docker run -it --rm -v "$PWD":/usr/src/mymaven -v "$HOME/.m2":/root/.m2 -v "$PWD/target:/usr/src/mymaven/target" -w /usr/src/mymaven maven:3.8.2-openjdk-8 mvn test -Ddriver.name=chromeRemoteDriver -Dremote.server=<local_ip_address>

Here, you must have to pass <local_ip_address> and the driver will be RemoteWebDriver.

nshthshah avatar Mar 21 '22 02:03 nshthshah