Skip to content

Commit 6a48cfc

Browse files
committed
moved in the webdriver 4 code to make this the main repo
1 parent 3f38ace commit 6a48cfc

File tree

9 files changed

+247
-304
lines changed

9 files changed

+247
-304
lines changed

.github/workflows/build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: build
2+
on:
3+
workflow_dispatch:
4+
push:
5+
schedule:
6+
- cron: '0 1 * * 6' # weekly check that it still works
7+
8+
env:
9+
BROWSER_STATE: Headless
10+
11+
jobs:
12+
compile-and-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
# https://github.com/actions/checkout
16+
- name: Download repository
17+
uses: actions/checkout@v3
18+
19+
# https://github.com/actions/setup-java
20+
- name: Set up JDK 18
21+
uses: actions/setup-java@v3
22+
with:
23+
distribution: 'temurin'
24+
java-version: 18
25+
26+
- name: setup chrome
27+
uses: browser-actions/setup-chrome@v1
28+
29+
- run: chrome --version
30+
31+
- name: Test with Maven
32+
run: mvn test

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Alan Richardson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,65 @@
1-
startUsingSeleniumWebDriver
1+
Start Using Selenium WebDriver
22
===========================
33

4-
**Recommend using the start Using Selenium 4 repo. This repo is for Selenium 3**
5-
- [Start Using Selenium 4](https://github.com/eviltester/startUsingSelenium4Java)
4+
[![build status](https://github.com/eviltester/startUsingSeleniumWebDriver/actions/workflows/build.yml/badge.svg)](https://github.com/eviltester/startUsingSeleniumWebDriver/actions)
65

6+
Simple start example for Selenium 4 with java and JUnit 5.
77

8-
**This repo is deprecated and based on WebDriver 3**
8+
- For previous versions of WebDriver and JUnit see the releases page.
99

10+
It has the basic startup and configuration for a test using Chrome Driver.
1011

11-
Source code to support getting started using Selenium WebDriver with Java
12+
## Pre-Requisites
1213

13-
The source code has only really been uploaded in case people encounter problems following the instructions or make a very simple mistake that they cannot figure out.
14+
Pre-requisites are ([use quick start guide to install these](https://github.com/eviltester/startUsingJavaJUnit5/blob/main/speedrun_install_java_checklist.md)):
1415

15-
Please read the comments below, and the source code comments if you are having trouble starting work with Firefox.
16+
- a Java SDK
17+
- maven
18+
- and and IDE Install.
1619

20+
The code uses JUnit 5 so you can follow the Quick Start Guide in the "[Getting Started with JUnit 5 repo](https://github.com/eviltester/startUsingJavaJUnit5)"
1721

18-
## Steps
22+
- [Quick start guide is here](https://github.com/eviltester/startUsingJavaJUnit5/blob/main/speedrun_install_java_checklist.md)
1923

20-
* First install Java, Maven and IntelliJ
21-
* [Java Install Checklist](https://github.com/eviltester/startUsingJavaJUnit/blob/master/speedrun_install_java_checklist.md)
22-
* Second install Firefox, GeckoDriver, Chrome and ChromeDriver
23-
* [WebDriver Install Checklist](https://github.com/eviltester/startUsingSeleniumWebDriver/blob/master/speedrun_install_checklist.md)
24+
## Start By
2425

26+
Clone or download the repo as a zip.
2527

26-
## Run a Test on your chosen browser
28+
From the unzipped top level directory containing the 'pom.xml' file, you can run the test using:
2729

28-
If you are on a mac and have allowed Remote Execution in the Safari browser then you can use the command line:
30+
`mvn test`
2931

30-
`mvn test -Dtest=MyFirstSafariTest`
32+
And can run it using headless mode by setting the environment variable `BROWSER_STATE` to have the value "`Headless`"
3133

32-
If you are using Chrome and have added ChromeDriver to the path then use the command line:
34+
e.g.
3335

34-
`mvn test -Dtest=MyFirstChromeTest`
36+
```
37+
BROWSER_STATE=Headless mvn test
38+
```
3539

36-
If you are using Firefox and have added GeckoDriver to the path then use the command line:
40+
## Use the code
3741

38-
`mvn test -Dtest=MyFirstTest`
42+
Open the project in Intellij by opening the folder containing the 'pom.xml' or open the 'pom.xml'.
3943

40-
Do not run `mvn test` because some of the tests are Platform and WebDriver version dependant and at least one will probably fail.
44+
## Github Actions
4145

42-
## Update `pom.xml`
46+
The repo also has [Github actions](https://github.com/eviltester/startUsingJavaJUnit5/blob/main/.github/workflows/build.yml) to run the test in headless mode periodically.
4347

44-
You may also wish to edit the `pom.xml` file and change the version of Selenium WebDriver to the current version listed on [seleniumhq.org](https://www.seleniumhq.org) in the [downloads section](https://www.seleniumhq.org/download/)
48+
## About Selenium WebDriver 4
4549

50+
This uses Selenium 4.
4651

47-
*Author: Alan Richardson*
52+
Selenium 4 comes with a builtin WebDriver Manager
4853

49-
* [EvilTester.com](https://eviltester.com)
50-
* [Compendium Developments](https://compendiumdev.co.uk)
54+
https://www.selenium.dev/blog/2022/introducing-selenium-manager/
5155

56+
This will automatically download the drivers required to allow Selenium to use the chosen webdriver.
5257

58+
e.g. if you instantiate a `new ChromeDriver()` the WebDriver Manager will download the drivers for
59+
Chrome and run the tests against Chrome.
5360

54-
## Running with Chrome
61+
You just need to download and have Chrome installed.
5562

56-
If you are using Chrome and have added ChromeDriver to the path then use the command line:
63+
Similarly, with Firefox and Edge, just download the browser and Selenium will download the correct driver.
5764

58-
`mvn test -Dtest=MyFirstChromeTest`
59-
60-
## Running with Firefox
61-
62-
If you are using Firefox and have added GeckoDriver to the path then use the command line:
63-
64-
`mvn test -Dtest=MyFirstTest`
65-
66-
## Earlier versions of Firefox
67-
68-
If you wish to use earlier versions of Firefox then see the repo:
69-
70-
https://github.com/eviltester/startUsingLegacyFirefoxWebDriver
7165

pom.xml

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,38 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>eviltester.com</groupId>
8-
<artifactId>MyFirstSeleniumIntelliJMaven</artifactId>
8+
<artifactId>startUsingSelenium4</artifactId>
99
<version>1.0</version>
1010

11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1113

12-
<!--
14+
<!-- add junit -->
15+
<junit.jupiter.version>5.6.2</junit.jupiter.version>
1316

14-
To run the Firefox test either right click on 'MyFirstTest' and run it, or at the command line type:
17+
<!-- configure the compiler via properties rather than plugin -->
18+
<maven.compiler.source>21</maven.compiler.source>
19+
<maven.compiler.target>21</maven.compiler.target>
1520

16-
`mvn test -Dtest=MyFirstTest`
21+
<!-- use maven surefire to run the tests -->
22+
<maven.surefire.version>3.2.5</maven.surefire.version>
1723

24+
<!-- to generate html junit reports for test phase -->
25+
<maven-site-plugin.version>4.0.0-M14</maven-site-plugin.version>
26+
<maven.surefire.report.version>3.2.5</maven.surefire.report.version>
1827

19-
To run the Chrome test either right click on 'MyFirstChromeTest' and run it, or at the command line type:
2028

21-
`mvn test -Dtest=MyFirstChromeTest`
29+
<!-- configure webdriver version -->
30+
<selenium-webdriver-version>4.20.0</selenium-webdriver-version>
31+
</properties>
32+
33+
<!--
34+
To run the Chrome test either right click on 'MyFirstChromeTest'
35+
and run it, or at the command line type:
2236
23-
If you type `mvn test` or try to run all the tests you will need to have all the drivers and browsers installed
37+
`mvn test -Dtest=MyFirstChromeTest`
2438
39+
If you type `mvn test` it will run all the tests.
2540
-->
2641

2742
<dependencies>
@@ -34,32 +49,64 @@
3449
<dependency>
3550
<groupId>org.seleniumhq.selenium</groupId>
3651
<artifactId>selenium-java</artifactId>
37-
<version>3.141.59</version>
52+
<version>${selenium-webdriver-version}</version>
53+
<scope>test</scope>
3854
</dependency>
3955

56+
<!-- adding the api and engine allow JUnit 5 to work -->
4057
<dependency>
41-
<groupId>junit</groupId>
42-
<artifactId>junit</artifactId>
43-
<version>4.12</version>
58+
<groupId>org.junit.jupiter</groupId>
59+
<artifactId>junit-jupiter-api</artifactId>
60+
<version>${junit.jupiter.version}</version>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-engine</artifactId>
66+
<version>${junit.jupiter.version}</version>
4467
<scope>test</scope>
4568
</dependency>
4669
</dependencies>
4770

48-
49-
<!-- added source version configuration because of reports of it compiling against Java 1.5 -->
5071
<build>
5172
<plugins>
73+
<!--
74+
Maven Surefire Plugin to run the Unit tests
75+
https://maven.apache.org/surefire/maven-surefire-plugin/usage.html
76+
-->
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-surefire-plugin</artifactId>
80+
<version>${maven.surefire.version}</version>
81+
</plugin>
82+
83+
<!--
84+
Maven Site Plugin to create the HTML site
85+
https://maven.apache.org/surefire/maven-surefire-plugin/usage.html
86+
-->
5287
<plugin>
5388
<groupId>org.apache.maven.plugins</groupId>
54-
<artifactId>maven-compiler-plugin</artifactId>
55-
<version>3.1</version>
56-
<configuration>
57-
<source>1.8</source>
58-
<target>1.8</target>
59-
<encoding>UTF-8</encoding>
60-
</configuration>
89+
<artifactId>maven-site-plugin</artifactId>
90+
<version>${maven-site-plugin.version}</version>
6191
</plugin>
92+
6293
</plugins>
6394
</build>
6495

96+
<!-- `mvn clean test site` to generate the junit html report in ./target/site -->
97+
<reporting>
98+
<plugins>
99+
<!--
100+
Maven Reports Plugin to generate the HTML reports
101+
https://maven.apache.org/surefire/maven-surefire-report-plugin/index.html
102+
-->
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-report-plugin</artifactId>
106+
<version>${maven.surefire.report.version}</version>
107+
</plugin>
108+
109+
</plugins>
110+
</reporting>
111+
65112
</project>

src/test/java/com/eviltester/webdriver/MyFirstChromeTest.java

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)