LoginSignup
1
0

More than 1 year has passed since last update.

[Set Up] Java + Selenium4 WebDriver + Chrome E2E test automation in windows by Eclipse

Last updated at Posted at 2022-03-22

Outline

Selenium Webdriverをもちいて、WEB (Chrome) のE2E テスト自動化を始めるにあたっての
環境構築のメモである

App List

APP Version Objective
Java Version 8 Update 321 Java
Eclipse 2021‑12 Java Programing Editor
Selenium Client 4.1.2 (January 30, 2022) Selenium
Chrome 99.0.4844.74 Web Browser
OS windows10 execution environment

Java

Javaの実行環境をダウンロードし、インストールする

download

Chrome WebDriver

Seleniumからchromeを起動するときのDriver
ほかのブラウザを使いたい場合は、そのブラウザに適したアプリ・プラグインをダウンロードする。

download

使用しているchromeのversionと同一のchromedriver.exeを用意する
https://www.selenium.dev/ja/documentation/webdriver/getting_started/install_drivers/

これを後ほど、eclipseの設定時に、chromediverを配置する。

Selenium Client

javaのselenium ライブラリ
現時点ではselenium4が安定版であり、このjavaのpackageをダウンロードする

download

javaのstable版 jarをdownloadする
https://www.selenium.dev/downloads/

Eclipse

Javaの開発、実行のためのツール

download

install

Eclipse IDE for Java Developersを選択
image.png

Create Project

chromeを起動するためのサンプルプログラムのプロジェクトを新規作成する。

image.png

Project Name 「SeleniumSampleProject」でnew projectを作成する

image.png

lib

seleniumのライブラリを今回作成したプロジェクトに紐づける。

Package Explorerで、SeleniumSampleProjectの配下に 「libs」のフォルダを新規作成する。
そこに、Selenium Clientのjar一式をcopy(drag)する
image.png

Java Build Path Classpath

Build Pathの設定を開き、Librariesの項目を選択する。
ここで、Classpathに、先ほどLibsに追加したライブラリを「Add External JARs」で追加する。

image.png

exe

downloadしてきた、chromedriverを配置する

image.png

Run Configurations compile option

Run configurationsの argumentsに、以下chromedriverのpathを設定する
この設定で、実行時にchromedriverをつかい、chromeを操作することができる。

-Dwebdriver.chrome.driver=exe/chromedriver.exe

image.png

sample program

chromeを起動し、楽天競馬のサイトに飛ばすsimpleなプログラム。
これにより、開発環境がただしく起動することの確認ができる。

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class SampleScript {

	public static void main (String[] args) {
		WebDriver driver = new ChromeDriver();
		driver.get("https://keiba.rakuten.co.jp");
		
	}
}

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0