[JAVA] Run Edge (Chromium version) on Mac with Selenium

Introduction

2020/06 Finally, the Chromium version of Edge is available via Windows Update. Recently, in E2E automated testing, requests to include IE have diminished. And soon even the 1st ** "I want to do automated testing (E2E)" → "With Internet Explorer" ** I hope that this trend will disappear from the world. Instead, ** Edge ** has increased.

Let's 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 スクリーンショット 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 thinking about anything. It's an easy victory. Naturally works 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"));
    }
}

Commentary

On the source, just because it's the Chromium version doesn't mean you need to rewrite it. The sources I've written for Edge will work, and Edge installed on MacOS will work as well.

Please note below. ..

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 throw an error Apparently it is set to platform: WINDOWS unconditionally. So, when testing with 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 Microsoft Edge.

Yes, No! </ Font> Do you need it? ?? It may be information, but ... By judging the part where special processing is inserted for each browser so far,


if (Browser name) then

Did you write something like that? ?? In my case, there is not a little of that kind of heritage in the past, and this was the reason why it just didn't work.

Supplement

Obviously, when launching a Selenium Grid node, it is necessary to specify the web driver. 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. That way, Node played a role without any problems without specifying a webdriver. However, for Chromium version Edge, it is mandatory to specify the web driver. (Probably, it works like going to refer to MicrosoftWebDriver.exe by default. It just starts the browser and stops without entering the URL)

Finally

You should now be able to test Edge installed on Mac OS. (I didn't write a big deal, but ww)

As for Windows, Microsoft Edge Legacy isn't up to IE, but it's still a bit quirky and couldn't run 100% on 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.

Recommended Posts

Run Edge (Chromium version) on Mac with Selenium
Run Ubuntu + ROS with Docker on Mac
Run STS4 on Mac
Steps to run docker on Mac
How to switch Java version with direnv in terminal on Mac
Steps to run local development of ASP.NET Core on Mac with docker-compose
Java version control with jenv on OSX
Create an ARM-cpu environment with qemu on mac and run java [Result → Failure]
Automate IE11 / Edge file downloads with Selenium WebDriver
Run JSP Hello World with Tomcat on Docker
Run an application made with Go on Heroku
How to run NullpoMino 7.5.0 on Ubuntu 20.04.1 64bit version
How to run javafx with Raspberry Pi Posted on 2020/07/12
Run Ruby on Rails RSpec tests with GitHub Actions
[2018 Preservation Version] Reverse Engineering Android App (.apk) on Mac
Until building Spring-Boot using Eclipse on Mac (Gradle version)
I struggled with pip install on an M1 Mac
Run kuromoji on Win10 + Eclipse + Java environment (January 2020 version)
Let's run the OpenVINO sample program on the OKI AI edge computer "AE2100" Ubuntu container version (1)
Let's run the OpenVINO sample program on the OKI AI edge computer "AE2100" Ubuntu container version (3)
Let's run the OpenVINO sample program on the OKI AI edge computer "AE2100" Ubuntu container version (2)