[Java] Move Edge (Chromium version) of Mac with Selenium

3 minute read

Introduction

2020/06 Finally, the Chromium version of Edge can be updated with Windows. Recently, in the E2E automatic test, the request to include IE has been reduced. And soon even the 1st ** “I want to do an automated test (E2E)” → “Internet Explorer” ** I hope that this trend will disappear from the world. Instead, Edge is increasing.

Now run the Chromium version of Edge on Mac OS

Development environment

OS

% sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.5
BuildVersion: 19F101

java

% java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment Corretto-11.0.7.10.1 (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.7.10.1 (build 11.0.7+10-LTS, mixed mode)

Edge

Screenshot 2020-07-08 2.53.58.png

build.gradle

// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group:'org.seleniumhq.selenium', name:'selenium-java', version: '3.141.59'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
compile group:'io.github.bonigarcia', name:'webdrivermanager', version: '4.0.0'

code

Local environment

public class SeleniumTestEnv {

    private WebDriver driver;

    @BeforeClass
    public static void beforeClass() throws Exception {
        WebDriverManager.edgedriver().setup();
    }

    @Before
    public void setUp() throws Exception {
        driver = new EdgeDriver();
    }

    @After
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void test001() {
        driver.get("https://www.humancrest.co.jp");
        //Test Code
    }

}

It’s a source I often see, but it works without any thought. It’s an easy victory. Works naturally on Windows

Selenium Grid

public class SeleniumTestEnvRemote {

    private RemoteWebDriver driver;

    @Before
    public void setUp() throws Exception {
// Capabilities capabilities = DesiredCapabilities.edge();
        MutableCapabilities option = new EdgeOptions();
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), option);
    }

    @After
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }

    @Test
    public void test001() {
        driver.get("https://www.humancrest.co.jp");
        String title = driver.getTitle();
        String browserName = driver.getCapabilities().getBrowserName();
        assertThat(title,is( "Human Crest Group"));
        assertThat(browserName,is("msedge"));
    }
}

Comment

Speaking of the source, it doesn’t need to be specially rewritten just because it became Chromium version. So far, the source I wrote for Edge will work, and the same will work for Edge installed on MacOS.

Below are the points to note. ..

Note 1

When specifying Edge with RemoteWebDriver,

DesiredCapabilities capabilities = DesiredCapabilities.edge();

If you write, it will be for Windows. In the log of Selenium Grid/hub set up on MacOS,

Error forwarding the new session cannot find :Capabilities {browserName: MicrosoftEdge, platform: WINDOWS, version:}

I get an error saying Apparently, it is unconditionally set as platform: WINDOWS. So, when testing on Edge on the Mac side,

DesiredCapabilities capabilities = DesiredCapabilities.edge();
capabilities.setPlatform(Platform.MAC);

Let’s add

Note 2

driver.getCapabilities().getBrowserName();

The return value of is msedge.

DesiredCapabilities.edge().getBrowserName()

The return value of is MicrosoftEdge.

Yes, No! Do you need it? ? It may be information that, Until now, by judging the place where the special processing for each browser is put,


if (browser name) then

Isn’t it written? ? In my case, this is the reason why there is no doubt that there is such a legacy of the past and it does not work.

Supplement

Of course, it is necessary to specify the webdriver when starting a Selenium Grid node. In other words like this

forMacOS


java -jar -Dwebdriver.edge.driver="msedgedriver" selenium-server-standalone-3.141.59.jar -role node -nodeConfig node_config.json

In my case, I put it sideways and put the webdriver of each browser in the same folder as selenium-server-standalone-xxx.jar. Then Node played the role without any problem even without specifying webdriver. However, for Chromium Edge, the web driver must be specified. (Probably, it works like going to refer to MicrosoftWebDriver.exe by default. It only starts the browser and stops without entering the URL)

Finally

You should now be able to test your Edge installed on MacOS as well. (I didn’t write a big deal, ww)

As for Windows, Microsoft Edge Legacy isn’t even IE, but it’s still a bit quirky, and I couldn’t run it with 100% the same source. However, the Chromium version runs on almost the same source as Chrome.

For E2E test automation engineers, it’s great to have an environment where Chrome, Firefox, and Edge can run on any OS.