I created a Selenium sample app that supports multiple browsers (Chrome, IE, Firefox) that runs in Java.

Overview

There are a lot of articles related to selenium, but this time I created a sample application that can be used for multi-browser tests etc. on Windows OS for the time being.

Execution environment

Windows10 Pro Eclipse IDE for Enterprise Java Developers JavaSE 11

Each browser version Chrome:84.0.4147 Firefox:78.0.2 InternetExplorer:11.959.18

How to use the sample app

1. 1. Sample application placement

Clone sample app

-Clone from the following URL and place it in the workspace folder of eclipse https://github.com/ZumWalt22/seleniumExp.git

-Import the cloned project from eclipse Import the project by selecting the directory cloned in File> Import> General> Import existing project to workspace

・ IE browser preset When executing with IE, please make the following settings in advance with a browser Internet Options → Security tab Check "Enable Protected Mode (requires restart of Internet Explorer)" for Internet, Local Intranet, Trusted Sites, and Restricted Sites Uncheck the "Enable Enhanced Protected Mode" checkbox

2. Sample app execution

1) Run the sample app from eclipse

Right-click on Project Explorer and click Run> 1. Run Java Application

2) Select the browser to execute

At the command prompt, you will be asked which browser to run as shown below. Enter the number of the browser you want to run and press the Enter key

input target test browser 0:Chrome 1:IE 2:FireFox >

・ Enter "0" when running on Chrome ・ Enter "1" when running with IE ・ Enter "2" when running with FireFox

3) The specified browser starts up and the browser is automatically executed by selenium.

The Google site starts up, the "selenium" string is set in the search box, and the sample that executes the search works image.png

How to change the driver library

When the driver of selenum server and each browser is changed, when it is executed by OS other than Windows Please refer to the information below and replace the file as appropriate.

1. 1. selenium server

Download from the URL below https://www.selenium.dev/downloads/ Click the "Selenium Server (Grid)" link to download

2. Each browser driver

・ Chrome driver

Download the driver from the URL below https://sites.google.com/a/chromium.org/chromedriver/downloads

On line 78 of the "seleniumEx.java" file, modify the path of the second argument of the following method to the path of the above location. System.setProperty("webdriver.chrome.driver", "selenium/chrome/83.0/chromedriver.exe");

・ IE driver

Download the driver from the URL below https://www.selenium.dev/downloads/

On line 99 of the "seleniumEx.java" file, modify the path of the second argument of the following method to the path of the above location. System.setProperty("webdriver.ie.driver", "selenium/ie/3.15/IEDriverServer.exe");

・ Firefox driver

Download the driver from the URL below https://github.com/mozilla/geckodriver/releases

On line 113 of the "seleniumEx.java" file, modify the path of the second argument of the following method to the path of the above location. System.setProperty("webdriver.gecko.driver", "C:/pleiades/workspace/seleniumExp/selenium/firefox/0.26/geckodriver.exe");

Reference material

Try starting Selenium2 in IE. https://qiita.com/tsuttie/items/372f5d4cad37650711f1

It was surprisingly easy to get started with Selenium https://qiita.com/kazokmr/items/0dc6b67e5a90ffc27db6

Recommended Posts

I created a Selenium sample app that supports multiple browsers (Chrome, IE, Firefox) that runs in Java.
I created a PDF in Java.
Create a docker image that runs a simple Java app
I wrote a Stalin sort that feels like a mess in Java
I made a shopify app @java
A simple sample callback in Java
A story about a Spring Boot project written in Java that supports Kotlin
Sample program that returns the hash value of a file in Java
Consolidate your JavaFX app into a jar that runs on both Java 8/11
When seeking multiple in a Java array
Create a TODO app in Java 7 Create Header
Try making a calculator app in Java