qmetry / qaf

Quality Automation Framework for web, mobileweb, mobile native and rest web-service using Selenium, webdrier, TestNG and Java Jersey
https://qmetry.github.io/qaf
MIT License
250 stars 136 forks source link

How can I use WebDriverManager in Docker? #406

Open nshthshah opened 2 years ago

nshthshah commented 2 years ago

QAF Version

3.1.0

Expected behavior

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

cjayswal commented 2 years ago

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

nshthshah commented 2 years ago

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 and the driver will be RemoteWebDriver.