├── .gitignore
├── README.md
├── install_notes.md
├── pom.xml
├── speedrun_install_checklist.md
└── src
└── test
└── java
└── com
└── eviltester
└── webdriver
├── MyFirstChromeTest.java
├── MyFirstSafariTest.java
└── MyFirstTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /target
3 | *.iml
4 | /.idea
5 | /tools
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | startUsingSeleniumWebDriver
2 | ===========================
3 |
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)
6 |
7 |
8 | **This repo is deprecated and based on WebDriver 3**
9 |
10 |
11 | Source code to support getting started using Selenium WebDriver with Java
12 |
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 |
15 | Please read the comments below, and the source code comments if you are having trouble starting work with Firefox.
16 |
17 |
18 | ## Steps
19 |
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 |
25 |
26 | ## Run a Test on your chosen browser
27 |
28 | If you are on a mac and have allowed Remote Execution in the Safari browser then you can use the command line:
29 |
30 | `mvn test -Dtest=MyFirstSafariTest`
31 |
32 | If you are using Chrome and have added ChromeDriver to the path then use the command line:
33 |
34 | `mvn test -Dtest=MyFirstChromeTest`
35 |
36 | If you are using Firefox and have added GeckoDriver to the path then use the command line:
37 |
38 | `mvn test -Dtest=MyFirstTest`
39 |
40 | Do not run `mvn test` because some of the tests are Platform and WebDriver version dependant and at least one will probably fail.
41 |
42 | ## Update `pom.xml`
43 |
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/)
45 |
46 |
47 | *Author: Alan Richardson*
48 |
49 | * [EvilTester.com](https://eviltester.com)
50 | * [Compendium Developments](https://compendiumdev.co.uk)
51 |
52 |
53 |
54 | ## Running with Chrome
55 |
56 | If you are using Chrome and have added ChromeDriver to the path then use the command line:
57 |
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
71 |
72 |
--------------------------------------------------------------------------------
/install_notes.md:
--------------------------------------------------------------------------------
1 | Installation on Windows 10 Notes:
2 | =================================
3 |
4 | * Using VM from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
5 | * `IEUser` / `Passw0rd!`
6 | * https://az792536.vo.msecnd.net/vms/release_notes_license_terms_8_1_15.pdf
7 | * used Chocolatey for JDK, IntelliJ, ChromeDriver and GeckoDriver Installs
8 |
9 |
10 | Installation on XP Notes:
11 | =========================
12 |
13 | - I installed using the Windows XP VM from modern.ie,
14 | with Java 1.7, maven 3.2.3, Webdriver 2.43.1, IntelliJ 13.1.5
15 |
16 | - need to use JDK 1.7, JDK 1.8 reports a warning on Windows XP
17 |
18 | - download a different text editor to edit the pom.xml (I used notepad++)
19 | - You may need to download a better editor than notepad.exe I use notepad++
20 | - download notepad ++ from
21 | http://notepad-plus-plus.org/download
22 |
23 | - You need to 'unblock' Java and the IDE etc.
24 | for the Windows Firewall as you run through the checklist.
25 | Do this, otherwise they won't be able to work
26 |
27 | - Edit SDK by right clicking and choosing "Open Module Settings",
28 | then edit the SDK for the Project and press [OK]
29 | - choose the location of the Java JDK you installed
30 | (sometimes you don't have to do this)
31 |
32 | + After test passes in the IDE - ignore the Info Message from WebDriver
33 |
34 | "Oct 07, 2014 10:40:36 AM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
35 | INFO: Command failed to close cleanly. Destroying forcefully (v2).
36 | org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@da44a7
37 |
38 | Process finished with exit code 0
39 | "
40 | It worked fine
41 |
42 |
43 | Installation on Mac Notes:
44 | ==========================
45 |
46 | - I installed using a VM with OS X Mavericks, then Java 1.8,
47 | maven 3.2.3, Webdriver 2.43.1, IntelliJ 13.1.5
48 |
49 | - slightly different order of the install than Windows because:
50 | I was prompted to install JDK when I typed "javac -version" so
51 | I followed the instructions at that point.
52 |
53 | I didn't need to install Firefox early because I could use the
54 | build in Safari browser to download software.
55 |
56 | I didn't need to install a separate text editor as the build in
57 | handled the pom.xml file fine.
58 |
59 | - with Maven
60 | - on mac, downloaded the zip
61 | - I didn't have a /usr/local so I had to "sudo mkdir /usr/local"
62 | - then I extracted the contents into an apache-maven-3.2.3 directory
63 | in /usr/local (I probably should have created an /apache-maven
64 | directory as well, but I didn't
65 |
66 | then I created all the exports in the terminal
67 |
68 | export M2_HOME=/usr/local/apache-maven-3.2.3
69 | export M2=$M2_HOME/bin
70 | export PATH=$M2:$PATH
71 |
72 | when I tried mvn -version it recognised maven but JAVA_HOME
73 | wasn't setup so I had to
74 |
75 | export JAVA_HOME="$(/usr/libexec/java_home)"
76 |
77 | Then it worked
78 |
79 | Then open a new tab and vi ~/.bash_profile and copy and paste
80 | in all the exports
81 |
82 | then create a new tab and "mvn --version" to check that it worked
83 |
84 | - Firefox
85 | searched for "firefox" then download from the mozilla.org site
86 | ran it
87 | nice overlapping dialogs that I had to deal with
88 |
89 | - when I ran "mvn test -Dtest=MyFirstTest", my wifi connection dropped
90 | in the middle, but I restarted wifi and ran the mvn command again
91 | and it completed fine - one reason to use Maven
92 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | eviltester.com
8 | MyFirstSeleniumIntelliJMaven
9 | 1.0
10 |
11 |
12 |
26 |
27 |
28 |
29 |
34 |
35 | org.seleniumhq.selenium
36 | selenium-java
37 | 3.141.59
38 |
39 |
40 |
41 | junit
42 | junit
43 | 4.12
44 | test
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | org.apache.maven.plugins
54 | maven-compiler-plugin
55 | 3.1
56 |
57 | 1.8
58 | 1.8
59 | UTF-8
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/speedrun_install_checklist.md:
--------------------------------------------------------------------------------
1 |
2 | # Generic Selenium WebDriver Install Speedrun checklist
3 |
4 | *Basic steps:*
5 |
6 | - Install Java and supporting tools
7 | - install Java JDK
8 | - install Maven
9 | - check Java and Maven work by running a sample test
10 | - Install IntelliJ
11 | - check IntelliJ works by running the sample test
12 | - Install WebDriver Supporting Tools
13 | - download and Install Chrome
14 | - download and Install Firefox
15 | - download and install Marionette GeckoDriver
16 | - download and Install ChromeDriver
17 | - check installs work by running the sample tests
18 |
19 | ---
20 |
21 | ## Install Videos
22 |
23 | *Windows Install Videos*
24 |
25 | * [YouTube Video Showing the Java Install on Windows 10](https://www.youtube.com/watch?v=j-46lYWAHF0)
26 | * https://www.youtube.com/watch?v=j-46lYWAHF0
27 | * [YouTube Video Showing the WebDriver Install on Windows 10](https://www.youtube.com/watch?v=gteqOBS_Ln4)
28 | * https://www.youtube.com/watch?v=gteqOBS_Ln4
29 |
30 | *Mac Install Videos*
31 |
32 | * [YouTube Video Showing the Java Install on a Mac](https://youtu.be/ff5ZsthcSZw)
33 | * https://youtu.be/ff5ZsthcSZw
34 | * [YouTube Video Showing the WebDriver Install on a Mac](https://youtu.be/nq97dfaVmC4)
35 | * https://youtu.be/nq97dfaVmC4
36 |
37 | ---
38 |
39 | # Windows Install Speedrun checklist
40 |
41 | ## Install Java Pre-requisites
42 |
43 | You need to have Java, Maven and IntelliJ installed.
44 |
45 | For instructions on how to install Java, Maven and IntelliJ; and check they are working, use the checklist in `startUsingJavaJunit` project:
46 |
47 | * [`startUsingJavaJunit` project](https://github.com/eviltester/startUsingJavaJUnit)
48 | * [Java Install Checklist](https://github.com/eviltester/startUsingJavaJUnit/blob/master/speedrun_install_java_checklist.md)
49 |
50 | **Note: I currently recommend using `ChromeDriver` as your default driver and the current version of Chrome as your default browser. If you only setup one driver and browser, make it Chrome, it is a lot easier to start with.**
51 |
52 |
53 | ---
54 |
55 | ## Install Firefox GeckoDriver or ChromeDriver the 'fast' way on Windows
56 |
57 | Both GeckoDriver and ChromeDriver are available to install via [Chocolatey](https://chocolatey.org/)
58 |
59 | - ChromeDriver
60 | - https://chocolatey.org/packages/selenium-chrome-driver
61 | - `choco install selenium-chrome-driver`
62 | - Firefox GeckoDriver
63 | - https://chocolatey.org/packages/selenium-gecko-driver
64 | - `choco install selenium-gecko-driver`
65 |
66 | ---
67 |
68 | ## Install Firefox GeckoDriver or ChromeDriver the 'long' way on Windows
69 |
70 | Note: You only really have to install one of these to get started. I recommend ChromeDriver and Chrome.
71 |
72 | ---
73 |
74 | ### Install Chrome and ChromeDriver on Windows
75 |
76 | * `[ ]`Install Current version of Chrome
77 | * `[ ]`download ChromeDriver add it to the path
78 | * https://sites.google.com/a/chromium.org/chromedriver/
79 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstChromeTest`
80 | * If you did everything correctly then Chrome should have started and a test should have run
81 |
82 | ---
83 |
84 | ### Install Firefox and GeckoDriver on Windows
85 |
86 | * `[ ]` Install Current version of Firefox
87 | * `[ ]`download GeckoDriver add it to the path
88 | * https://github.com/mozilla/geckodriver
89 | * https://github.com/mozilla/geckodriver/releases
90 | * Unzip the downloaded archive file and add to the windows path
91 | - `geckodriver.exe`
92 | * Check that you have added to the path by typing `geckodriver` into a command prompt
93 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstTest`
94 | * If you did everything correctly then Firefox should have started and a test should have run
95 |
96 | ---
97 |
98 | ## Install Sample WebDriver Project on Windows
99 |
100 | * `[ ]`Download Test Project (this has a simple pom.xml and a basic test to run)
101 | * `[ ]`visit https://github.com/eviltester/startUsingSeleniumWebDriver
102 | * `[ ]`download the zip file and unzip somewhere
103 |
104 | * `[ ]`Install and run IntelliJ Community Edition
105 |
106 | * `[ ]`open project for the unzipped pom.xml file
107 |
108 | ---
109 |
110 | * Check the most up to date version of WebDriver
111 | * `[ ]`check for most up to date version of WebDriver in the unzipped pom.xml file
112 | * `[ ]`check the webdriver downloads page or the maven page for the up to date version
113 | - https://www.seleniumhq.org/download/
114 | * `[ ]`amend the pom.xml file if the version number is not up to date
115 | * `[ ]`exit IntelliJ
116 |
117 | The version number is contained in this section of the `pom.xml` e.g. this says use version `3.13.0` of Selenium WebDriver
118 |
119 | ~~~~~~~~
120 |
121 | org.seleniumhq.selenium
122 | selenium-java
123 | 3.13.0
124 |
125 | ~~~~~~~~
126 |
127 | ---
128 |
129 | ## Run Test From IDE on Windows
130 |
131 | * `[ ]`Back in IntelliJ
132 |
133 | * `[ ]`run MyFirstTest, or MyFirstTestFF48 or MyFirstChromeTest class
134 | * `[ ]`right click on the class in the project window and select "Run
135 |
136 | * `[ ]`When the test runs from the IDE, you are finished your install and setup
137 |
138 | ---
139 |
140 | # Mac Install Speedrun checklist - Homebrew
141 |
142 | ## Install Java Pre-requisites
143 |
144 | For instructions on how to install Java, Maven and IntelliJ; and check they are working, use the checklist in `startUsingJavaJunit` project:
145 |
146 | * [`startUsingJavaJunit` project](https://github.com/eviltester/startUsingJavaJUnit)
147 | * [Java Install Checklist](https://github.com/eviltester/startUsingJavaJUnit/blob/master/speedrun_install_java_checklist.md)
148 |
149 | ---
150 |
151 | ## Install WebDriver Sample Project on Mac
152 |
153 | * `[ ]`Install Java JDK, Maven - see [`startUsingJavaJunit` project](https://github.com/eviltester/startUsingJavaJUnit)
154 | * `[ ]`Install IntelliJ Community Edition - see [`startUsingJavaJunit` project](https://github.com/eviltester/startUsingJavaJUnit)
155 |
156 | * `[ ]`Download Test Project (this has a simple pom.xml and a basic test to run)
157 | * `[ ]`visit https://github.com/eviltester/startUsingSeleniumWebDriver
158 | * `[ ]`download the zip file and unzip somewhere
159 |
160 |
161 | **Note: Currently recommend using `ChromeDriver` as your default driver and the current version of Chrome as your default browser. If you only setup one driver and browser, make it Chrome, it is a lot easier to start with.**
162 |
163 | ---
164 |
165 | * `[ ]`open project for the unzipped pom.xml file
166 |
167 | * `[ ]`check most up to date version of webdriver in the unzipped pom.xml file
168 | * `[ ]`check the [Selenium webdriver downloads](https://www.selenium.dev/downloads/) page for the up to date version
169 | * I do not recommend using a beta version
170 | * `[ ]`amend the `pom.xml` file if the version number is not up to date
171 | * `[ ]`exit IntelliJ
172 |
173 | ---
174 |
175 | ## Install SafarDriver on Mac
176 |
177 | SafariDriver is built into the Mac operating system.
178 |
179 | We need to enable remote execution in Safari Browser to use it.
180 |
181 | - `Safari \ Preferences \ Advanced`
182 | - `[x]` show develop menu in menu bar
183 | - `Develop \ Allow Remote Execution`
184 |
185 | ---
186 |
187 | ## Install Firefox and GeckoDriver on Mac
188 |
189 | [Install Homebrew](https://brew.sh/) if you don't already have it.
190 |
191 | * `[ ]` Install Current version of Firefox
192 | * either with cask `brew cask install firefox`
193 | * or visit the site and install
194 | * `[ ]` Install GeckoDriver
195 | - https://brew.sh/
196 | - https://formulae.brew.sh/formula/geckodriver
197 | * `brew install geckodriver`
198 |
199 | Note: to upgrade use `brew cask upgrade`
200 |
201 | ---
202 |
203 | ## Install Chrome and ChromeDriver on Mac
204 |
205 | * `[ ]`Install Current version of Chrome
206 | * either with cask `brew cask install google-chrome`
207 | * or visit the site and install
208 | * `[ ]` Install ChromeDriver using HomeBrew
209 | * https://brew.sh/
210 | - https://formulae.brew.sh/cask/chromedriver#default
211 | * `brew cask install chromedriver`
212 |
213 | Note: to upgrade use `brew cask upgrade`
214 |
215 | ---
216 |
217 | ## Install Firefox GeckoDriver or ChromeDriver the 'long' way on Mac
218 |
219 | Remember you can skip this step if you used HomeBrew.
220 |
221 | ### Firefox GeckoDriver the 'long' way on Mac
222 |
223 | * `[ ]`download GeckoDriver add it to the path
224 | * https://github.com/mozilla/geckodriver
225 | * https://github.com/mozilla/geckodriver/releases
226 | * extract into a folder
227 | * if using version 2.53.1 of WebDriver then rename to wires
228 | * if using version 3 of WebDriver then leave as geckodriver
229 | * add path to `.bash_profile`
230 | * `export PATH=$PATH:/folder/you/extracted/it/to`
231 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstTestFF48`
232 |
233 | ---
234 |
235 | ### ChromeDriver the 'long' way on Mac
236 |
237 | * `[ ]` Install ChromeDriver
238 | * `[ ]`download ChromeDriver add it to the path
239 | * https://sites.google.com/a/chromium.org/chromedriver/
240 | * extract into a folder
241 | * add folder path to `.bash_profile`
242 | * `export PATH=$PATH:/folder/you/extracted/it/to`
243 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstChromeTest`
244 |
245 | ---
246 |
247 | ## Run Test From IDE on Windows or Mac
248 |
249 | * `[ ]` Back in IntelliJ
250 |
251 | * `[ ]` run `MyFirstTest`, or `MyFirstChromeTest` or `MyFirstSafariTest` class depending on which drivers you installed
252 | * `[ ]`right click on the class in the project window and select "Run
253 |
254 | * `[ ]`When the test runs from the IDE, you are finished your install and setup
255 |
256 | > **Note: on mac if you experience an error running ChromeDriver `"chromedriver" cannot be opened because the developer cannot be verified.`** then try the answers here:** https://stackoverflow.com/questions/60362018/
257 | >
258 | > - I use `which chromedriver` to find out where chromedriver is installed
259 | > - `cd /usr/local/Caskroom/chromedriver/` to go to chromedriver install
260 | > - `ls` to find out the version of chromedriver then
261 | > - `cd 83.0.4103.39` where `82.0.4103.39` was the version shown when I typed `ls`
262 | > - then `xattr -d com.apple.quarantine chromedriver`
263 | >
264 | > Short cut command for this `xattr -d com.apple.quarantine $(which chromedriver)`
265 |
266 |
267 | ---
268 |
269 |
270 |
271 |
272 | Generic Links:
273 | ==============
274 |
275 |
276 | + sample JUnit test project from
277 | * https://github.com/eviltester/startUsingJavaJUnit
278 | * [Java Install Checklist](https://github.com/eviltester/startUsingJavaJUnit/blob/master/speedrun_install_java_checklist.md)
279 |
280 | + Download IntelliJ from
281 | * http://www.jetbrains.com/idea/download/
282 |
283 | + sample webdriver test project from
284 | * https://github.com/eviltester/startUsingSeleniumWebDriver
285 |
286 | ---
287 |
288 | + Check current webdriver version from
289 | * https://www.selenium.dev/downloads/
290 |
291 | + ChromeDriver
292 | * https://sites.google.com/a/chromium.org/chromedriver/
293 |
294 | + Mozilla GeckoDriver
295 | * https://github.com/mozilla/geckodriver
296 | * https://github.com/mozilla/geckodriver/releases
297 |
298 | + Mac HomeBrew and Cask
299 | * https://brew.sh
300 | * https://caskroom.github.io/
301 |
302 |
303 | ---
304 |
305 | # Selenium Simplified
306 |
307 | ## Online Training and blog teaching Selenium WebDriver with Java
308 |
309 | * www.seleniumsimplified.com
310 |
311 | By Alan Richardson
312 |
313 | * www.eviltester.com
314 | * www.javafortesters.com
315 | * www.compendiumdev.co.uk
316 | * https://uk.linkedin.com/in/eviltester
317 | * [@eviltester](https://twitter.com/eviltester)
318 |
319 |
320 |
321 | ---
322 |
323 | ## Legacy Firefox install instructions
324 |
325 | * `[ ]` If install ESR version of Firefox (45) https://www.mozilla.org/en-US/firefox/organizations/faq/
326 | * `[ ]`no need to download any extra drivers
327 | * if using WebDriver `2.53.1`
328 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstTest`
329 | * if using WebDriver `3.0.1` (or above)
330 | * `[ ]`in startUsingSeleniumWebDriver folder run command `mvn test -Dtest=MyFirstLegacyFFTest`
--------------------------------------------------------------------------------
/src/test/java/com/eviltester/webdriver/MyFirstChromeTest.java:
--------------------------------------------------------------------------------
1 | package com.eviltester.webdriver;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openqa.selenium.By;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.chrome.ChromeDriver;
8 |
9 | public class MyFirstChromeTest {
10 |
11 | /**
12 |
13 | The following code is for the Chrome Driver.
14 |
15 | You also need to download the ChromeDriver executable:
16 |
17 | - https://sites.google.com/a/chromium.org/chromedriver/
18 |
19 | You can easily install Chromedriver on windows using chocolatey:
20 |
21 | - https://chocolatey.org/packages?q=ChromeDriver
22 |
23 | If you are on a Mac then you could install ChromeDriver using HomeBrew
24 |
25 | - https://brew.sh/
26 | - https://formulae.brew.sh/cask/chromedriver#default
27 |
28 | ~~~~~~~~
29 | brew update
30 | brew cask install chromedriver
31 | ~~~~~~~~
32 |
33 | And keeping it up to date
34 |
35 | ~~~~~~~~
36 | brew cask upgrade chromedriver
37 | ~~~~~~~~
38 |
39 | */
40 |
41 | @Test
42 | public void startWebDriver(){
43 |
44 |
45 | /**
46 |
47 | if you have not added ChromeDriver to the path then you need to tell Selenium WebDriver where
48 | the executable of the driver is located. You can do that using code like the following
49 |
50 | The `chromeDriverLocation` string should be the actual physical path of the executable.
51 |
52 | If you installed through Chocolatey or Homebrew then you should not need the following lines as the
53 | executable will be on your path.
54 |
55 | You can tell if the executable is on your path by typing `chromedriver` into a command prompt and if it is
56 | a recognised command then it is on your path.
57 | */
58 |
59 | // String currentDir = System.getProperty("user.dir");
60 | // String chromeDriverLocation = currentDir + "/tools/chromedriver/chromedriver.exe";
61 | // System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
62 |
63 | //If you add the folder with chromedriver.exe to the path then you only need the following line
64 | // and you don't need to set the property as listed in the 3 lines above
65 | // e.g. D:\Users\Alan\Documents\github\startUsingSeleniumWebDriver\tools\chromedriver
66 |
67 | WebDriver driver = new ChromeDriver();
68 |
69 | driver.navigate().to("https://testpages.eviltester.com/styled/basic-web-page-test.html");
70 |
71 | Assert.assertEquals(
72 | "Basic Web Page Example",
73 | driver.findElement(By.tagName("h1")).getText()
74 | );
75 |
76 | driver.close();
77 | driver.quit();
78 | }
79 |
80 | /*
81 |
82 | if https://testpages.herokuapp.com is not working then you can download the
83 | test pages app from github
84 |
85 | https://github.com/eviltester/TestingApp/tree/master/java/testingapps/seleniumtestpages
86 |
87 | The herokuapp and github release are maintained.
88 |
89 | You can also find legacy test pages at:
90 |
91 | - https://compendiumdev.co.uk/selenium/testpages
92 | - https://www.seleniumsimplified.com/testpages/
93 |
94 | If you want to learn more about Selenium WebDriver then check out my online courses:
95 |
96 | https://eviltester.com/courses
97 |
98 | */
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/test/java/com/eviltester/webdriver/MyFirstSafariTest.java:
--------------------------------------------------------------------------------
1 | package com.eviltester.webdriver;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openqa.selenium.By;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.safari.SafariDriver;
8 |
9 | public class MyFirstSafariTest {
10 |
11 |
12 | /**
13 |
14 | The following code is for the Safari Driver.
15 |
16 | This will only work on a Mac operating system.
17 |
18 | The safari driver is installed by default with the operating system. It should just work on a mac.
19 |
20 | You may need to change the safari properties to allow automated execution.
21 |
22 | - Safari \ Preferences \ Advanced \ [x] show develop menu in menu bar
23 | - Develop \ Allow Remote Execution
24 |
25 | */
26 |
27 | @Test
28 | public void startWebDriver(){
29 |
30 | WebDriver driver = new SafariDriver();
31 |
32 | driver.navigate().to("https://testpages.eviltester.com/styled/basic-web-page-test.html");
33 |
34 | Assert.assertEquals(
35 | "Basic Web Page Example",
36 | driver.findElement(By.tagName("h1")).getText()
37 | );
38 |
39 | // safari driver now seems to prefer just close or quit, but not both
40 | //driver.close();
41 | driver.quit();
42 | }
43 |
44 |
45 | /*
46 |
47 | if https://testpages.herokuapp.com is not working then you can download the
48 | test pages app from github
49 |
50 | https://github.com/eviltester/TestingApp/tree/master/java/testingapps/seleniumtestpages
51 |
52 | The herokuapp and github release are maintained.
53 |
54 | You can also find legacy test pages at:
55 |
56 | - https://compendiumdev.co.uk/selenium/testpages
57 | - https://www.seleniumsimplified.com/testpages/
58 |
59 | If you want to learn more about Selenium WebDriver then check out my online courses:
60 |
61 | https://eviltester.com/courses
62 |
63 | */
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/com/eviltester/webdriver/MyFirstTest.java:
--------------------------------------------------------------------------------
1 | package com.eviltester.webdriver;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 | import org.openqa.selenium.By;
6 | import org.openqa.selenium.WebDriver;
7 | import org.openqa.selenium.firefox.FirefoxDriver;
8 |
9 | public class MyFirstTest {
10 |
11 | /**
12 |
13 | The following code is for the FirefoxDriver.
14 |
15 | You also need to download the GeckoDriver executable:
16 |
17 | - https://github.com/mozilla/geckodriver/releases
18 |
19 | You can easily install GeckoDriver on windows using chocolatey:
20 |
21 | - https://chocolatey.org/packages/selenium-gecko-driver
22 |
23 | If you are on a Mac then you could install Firefox GeckoDriver using HomeBrew
24 |
25 | - https://brew.sh/
26 | - https://formulae.brew.sh/formula/geckodriver
27 |
28 | ~~~~~~~~
29 | brew update
30 | brew install geckodriver
31 | ~~~~~~~~
32 |
33 | And to keep it up to date:
34 |
35 | ~~~~~~~~
36 | brew update
37 | brew upgrade geckodriver
38 | ~~~~~~~~
39 |
40 |
41 |
42 | */
43 |
44 | @Test
45 | public void startWebDriver(){
46 |
47 | WebDriver driver = new FirefoxDriver();
48 |
49 | driver.navigate().to("https://testpages.eviltester.com/styled/basic-web-page-test.html");
50 |
51 | Assert.assertEquals(
52 | "Basic Web Page Example",
53 | driver.findElement(By.tagName("h1")).getText()
54 | );
55 |
56 | // FirefoxDriver seems to prefer either quit or close, but sometimes throws an error if you use both
57 | //driver.close();
58 | driver.quit();
59 | }
60 |
61 | /*
62 |
63 | if https://testpages.herokuapp.com is not working then you can download the
64 | test pages app from github
65 |
66 | https://github.com/eviltester/TestingApp/tree/master/java/testingapps/seleniumtestpages
67 |
68 | The herokuapp and github release are maintained.
69 |
70 | You can also find legacy test pages at:
71 |
72 | - https://compendiumdev.co.uk/selenium/testpages
73 | - https://www.seleniumsimplified.com/testpages/
74 |
75 | If you want to learn more about Selenium WebDriver then check out my online courses:
76 |
77 | https://eviltester.com/courses
78 |
79 | */
80 | }
81 |
--------------------------------------------------------------------------------