Member-only story
Run your tests in Safari without a MAC
No MAC, don’t worry you can still run your tests in Safar with this.
If you google the most popular browser in 2021, Safari is the second most popular browser, which is the native browser of apple devices. It is the world’s faster browser according to Apple. Therefore, it is a must browser that we should test our product. The biggest challenge of testing in safari is you need to have a MAC whether you carry out the manual or automated testing. In other words, Safari is platform-specific.
Here is the no-brainer cost-effective mechanism to run your tests on Safari.
WebDriverManager is a library that is popular and widely used by automation frameworks to avoid the extra hassle of managing different drivers.
With their recent release (v5.0.3), they started supporting dockerized browsers, which they call Browsers in Docker.
They support Chrome, Firefox, Edge, Opera, and Safari browsers as Docker containers in WebDriverManager.
How to use Safari Docker container for test execution
Pre-requisite
First, you need to install Docker from https://www.docker.com/ in your test execution machines.
Implementation
Add the following dependency in your POM, or if you are already using webdrivermanager, upgrade to 5.0.3
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
Then, you need to add the below code wherever you initiate the Safari driver for the tests to run.
WebDriverManager wdm = WebDriverManager.chromedriver().browserInDocker();
WebDriver driver = wdm.create();
Sample Test
@Test
public void safari() throws Exception {
driver = BrowserFactory.getBrowser("safari");
driver.manage().window().maximize();
driver.get("https://www.google.com/");
}
Now, when you are running your suite, WebDriverManager will pull the Safari image from Docker Hub, which will take few minutes when you are running it for the first…