[Java] I created a Selenium sample application that supports multiple browsers (Chrome, IE, Firefox) that runs on Java.

3 minute read

Overview

There are many selenium-related articles, but this time I created a sample application that can be diverted for Windows OS for crisp multi-browser test etc. *It can be implemented in Chrome, IE, FireFox *Assumed to be executed from eclipse

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. Sample application placement

Clone the 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 where you cloned the existing project into the workspace by selecting File> Import> General> Workspace

  • Firefox driver does not work unless the full path is specified, so modify it accordingly (seleniumEx.java line 113) Sample code is written assuming that the project “seleniumExp” is cloned in “C:/pleiades/workspace/”

・IE browser preset If you want to run in IE, please make the following settings in advance in your browser Internet Options → Security tab Check “Enable Protected Mode (requires a restart of Internet Explorer)” for Internet, local intranet, trusted sites, and restricted sites Uncheck the “Enable Extended Protected Mode” checkbox

2. Sample application execution

1) Run the sample app from eclipse

Right-click the project explorer and click “Run”> “1. Run Java Application”

2) Select the target browser

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

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

・Enter “0” when operating on Chrome ・Enter “1” when operating in IE ・Enter “2” when operating with FireFox

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

The Google site is launched, the “selenium” string is set in the search box, and the sample that the search is executed works image.png

How to change driver library

When the driver of the selenum server and each browser has changed, or when operating on an OS other than Windows Please refer to the information below and replace the files as appropriate.

1. selenium server

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

  • Download “Latest stable version 3.141.59” for this sample app. Place the jar under the “lib”> “jar” folder below in the seleniumExp project Add the JAR placed in “Add JAR” from Java Build Path> Library

2. Each browser driver

・Chrome driver

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

  • In this sample application, download “ChromeDriver 83.0.4103.39” chromedriver_win32.zip Placed an arbitrary folder name (version etc.) under the following “selenium”> “chrome” folder of seleniumExp project

Line 78 of “seleniumEx.java” file, corrected the second argument path of the following method to the above location path System.setProperty(“webdriver.chrome.driver”, “selenium/chrome/83.0/chromedriver.exe”);

#####-IE driver Download the driver from the following URL https://www.selenium.dev/downloads/ *For this sample application, download “The Internet Explorer Driver Server” “Download version 3.150.1” IEDriverServer_Win32_3.150.1.zip Placed an arbitrary folder name (version etc.) under the “selenium”> “ie” folder below in the seleniumExp project

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

· Firefox driver

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

  • Download geckodriver-v0.26.0-win32.zip for this sample application Place any folder name (version etc.) under the following “selenium”> “firefox” folder of seleniumExp project

113th line of “seleniumEx.java” file, corrected the second argument path of the following method to the above location path System.setProperty(“webdriver.gecko.driver”, “C:/pleiades/workspace/seleniumExp/selenium/firefox/0.26/geckodriver.exe”); *FireFox driver location must be described in full path

References

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

It was surprisingly easy to start using Selenium https://qiita.com/kazokmr/items/0dc6b67e5a90ffc27db6