Skip to content

Commit 5648986

Browse files
author
Mat Walker
committed
Fixed issue with Selenium Driver logging and added tests to verify
1 parent 29c9d67 commit 5648986

File tree

6 files changed

+308
-18
lines changed

6 files changed

+308
-18
lines changed

.gitignore

Lines changed: 202 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,156 @@
1+
2+
# Created by https://www.gitignore.io/api/osx,java,eclipse,intellij,maven
3+
4+
### Eclipse ###
5+
6+
.metadata
7+
bin/
8+
tmp/
9+
*.tmp
10+
*.bak
11+
*.swp
12+
*~.nib
13+
local.properties
14+
.settings/
15+
.loadpath
16+
.recommenders
17+
18+
# External tool builders
19+
.externalToolBuilders/
20+
21+
# Locally stored "Eclipse launch configurations"
22+
*.launch
23+
24+
# PyDev specific (Python IDE for Eclipse)
25+
*.pydevproject
26+
27+
# CDT-specific (C/C++ Development Tooling)
28+
.cproject
29+
30+
# CDT- autotools
31+
.autotools
32+
33+
# Java annotation processor (APT)
34+
.factorypath
35+
36+
# PDT-specific (PHP Development Tools)
37+
.buildpath
38+
39+
# sbteclipse plugin
40+
.target
41+
42+
# Tern plugin
43+
.tern-project
44+
45+
# TeXlipse plugin
46+
.texlipse
47+
48+
# STS (Spring Tool Suite)
49+
.springBeans
50+
51+
# Code Recommenders
52+
.recommenders/
53+
54+
# Annotation Processing
55+
.apt_generated/
56+
57+
# Scala IDE specific (Scala & Java development for Eclipse)
58+
.cache-main
59+
.scala_dependencies
60+
.worksheet
61+
62+
### Eclipse Patch ###
63+
# Eclipse Core
64+
.project
65+
66+
# JDT-specific (Eclipse Java Development Tools)
67+
.classpath
68+
69+
# Annotation Processing
70+
.apt_generated
71+
72+
.sts4-cache/
73+
74+
### Intellij ###
75+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
76+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
77+
78+
# User-specific stuff
79+
.idea/**/workspace.xml
80+
.idea/**/tasks.xml
81+
.idea/**/usage.statistics.xml
82+
.idea/**/dictionaries
83+
.idea/**/shelf
84+
85+
# Generated files
86+
.idea/**/contentModel.xml
87+
88+
# Sensitive or high-churn files
89+
.idea/**/dataSources/
90+
.idea/**/dataSources.ids
91+
.idea/**/dataSources.local.xml
92+
.idea/**/sqlDataSources.xml
93+
.idea/**/dynamic.xml
94+
.idea/**/uiDesigner.xml
95+
.idea/**/dbnavigator.xml
96+
97+
# Gradle
98+
.idea/**/gradle.xml
99+
.idea/**/libraries
100+
101+
# Gradle and Maven with auto-import
102+
# When using Gradle or Maven with auto-import, you should exclude module files,
103+
# since they will be recreated, and may cause churn. Uncomment if using
104+
# auto-import.
105+
# .idea/modules.xml
106+
# .idea/*.iml
107+
# .idea/modules
108+
109+
# CMake
110+
cmake-build-*/
111+
112+
# Mongo Explorer plugin
113+
.idea/**/mongoSettings.xml
114+
115+
# File-based project format
116+
*.iws
117+
118+
# IntelliJ
119+
out/
120+
121+
# mpeltonen/sbt-idea plugin
122+
.idea_modules/
123+
124+
# JIRA plugin
125+
atlassian-ide-plugin.xml
126+
127+
# Cursive Clojure plugin
128+
.idea/replstate.xml
129+
130+
# Crashlytics plugin (for Android Studio and IntelliJ)
131+
com_crashlytics_export_strings.xml
132+
crashlytics.properties
133+
crashlytics-build.properties
134+
fabric.properties
135+
136+
# Editor-based Rest Client
137+
.idea/httpRequests
138+
139+
# Android studio 3.1+ serialized cache file
140+
.idea/caches/build_file_checksums.ser
141+
142+
### Intellij Patch ###
143+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
144+
145+
# *.iml
146+
# modules.xml
147+
# .idea/misc.xml
148+
# *.ipr
149+
150+
# Sonarlint plugin
151+
.idea/sonarlint
152+
153+
### Java ###
1154
# Compiled class file
2155
*.class
3156

@@ -13,10 +166,58 @@
13166
# Package Files #
14167
*.jar
15168
*.war
169+
*.nar
16170
*.ear
17171
*.zip
18172
*.tar.gz
19173
*.rar
20174

21175
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22-
hs_err_pid*
176+
hs_err_pid*
177+
178+
### Maven ###
179+
target/
180+
pom.xml.tag
181+
pom.xml.releaseBackup
182+
pom.xml.versionsBackup
183+
pom.xml.next
184+
release.properties
185+
dependency-reduced-pom.xml
186+
buildNumber.properties
187+
.mvn/timing.properties
188+
.mvn/wrapper/maven-wrapper.jar
189+
190+
### OSX ###
191+
# General
192+
.DS_Store
193+
.AppleDouble
194+
.LSOverride
195+
196+
# Icon must end with two \r
197+
Icon
198+
199+
# Thumbnails
200+
._*
201+
202+
# Files that might appear in the root of a volume
203+
.DocumentRevisions-V100
204+
.fseventsd
205+
.Spotlight-V100
206+
.TemporaryItems
207+
.Trashes
208+
.VolumeIcon.icns
209+
.com.apple.timemachine.donotpresent
210+
211+
# Directories potentially created on remote AFP share
212+
.AppleDB
213+
.AppleDesktop
214+
Network Trash Folder
215+
Temporary Items
216+
.apdisk
217+
218+
219+
# End of https://www.gitignore.io/api/osx,java,eclipse,intellij,maven
220+
221+
#Log files
222+
223+
TestServer/*.txt

Controlium.iml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
33
<component name="ExternalSystem" externalSystem="Maven" />
4-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_10">
4+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
55
<output url="file://$MODULE_DIR$/target/classes" />
66
<output-test url="file://$MODULE_DIR$/target/test-classes" />
77
<content url="file://$MODULE_DIR$">
88
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
99
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
1010
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
11-
<sourceFolder url="file://$MODULE_DIR$/src/Test" isTestSource="true" />
11+
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
1212
<excludeFolder url="file://$MODULE_DIR$/target" />
1313
</content>
1414
<orderEntry type="inheritedJdk" />
1515
<orderEntry type="sourceFolder" forTests="false" />
16+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.10.0" level="project" />
17+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.10.0" level="project" />
18+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.10.0" level="project" />
19+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.10.0" level="project" />
20+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.10.0" level="project" />
21+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.10.0" level="project" />
22+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.10.0" level="project" />
23+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.10.0" level="project" />
24+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.10.0" level="project" />
25+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.10.0" level="project" />
26+
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.7.9" level="project" />
27+
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
28+
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
29+
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
30+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" />
31+
<orderEntry type="library" name="Maven: com.google.guava:guava:23.6-jre" level="project" />
32+
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
33+
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />
34+
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.1.3" level="project" />
35+
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
36+
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
37+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.3" level="project" />
38+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />
39+
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.9.1" level="project" />
40+
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.13.0" level="project" />
41+
<orderEntry type="library" name="Maven: org.teamcontrolium:utilities:1.1.0" level="project" />
1642
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.11.0" level="project" />
1743
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.11.0" level="project" />
1844
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.11.0" level="project" />

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
</dependency>
9494
</dependencies>
9595
<properties>
96-
<maven.compiler.source>1.6</maven.compiler.source>
97-
<maven.compiler.target>1.6</maven.compiler.target>
96+
<maven.compiler.source>1.8</maven.compiler.source>
97+
<maven.compiler.target>1.8</maven.compiler.target>
9898
</properties>
9999

100100
<developers>

src/Test/TeamControlium/Controlium/Test/BasicNavigationAndFindTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,17 @@ void VerifyCorrectErrorWithBadFindLogicWithFriendlyName() {
150150
@org.junit.jupiter.api.Test
151151
void VerifyUnstableElementTimeout() {
152152
seleniumDriver.setFindTimeout(Duration.ofMillis(10000));
153+
//
154+
// At bouncejs.com there is an element in the left preferences panel that is constantly moving up and down. So it is NEVER stable. So we can check that
155+
// findElement fails if told to wait untile stable.
156+
//
157+
ObjectMapping movingElement = new ObjectMapping("//div[@id='preferences']/div[@class='empty-message']","Moving element in left preferences panel");
153158
seleniumDriver.gotoURL("http://bouncejs.com/");
154159
HTMLElement element=null;
155160
String errorMessage=null;
156161
StopWatch stopWatch = StopWatch.createStarted();
157162
try {
158-
element = seleniumDriver.findElement(new ObjectMapping("//div[@id='preferences']/div[@class='empty-message']","Moving element in left preferences panel"),true);
163+
element = seleniumDriver.findElement(movingElement,true);
159164
}
160165
catch( Exception e) {
161166
stopWatch.stop();

src/Test/TeamControlium/Controlium/Test/SeleniumServerTests.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import java.io.BufferedReader;
1010
import java.io.InputStreamReader;
11+
import java.nio.charset.Charset;
12+
import java.nio.file.Files;
13+
import java.nio.file.Paths;
1114
import java.util.ArrayList;
1215
import java.util.List;
1316

@@ -42,6 +45,61 @@ void VerifySeleniumDriverLaunchesChromeAsDefault() {
4245
Assertions.assertEquals(chromeCountBefore,chromeCountAfter-1,"Number of Chrome Driver instances increments");
4346
}
4447

48+
49+
// Verify Selenium can be launched locally with logging
50+
@org.junit.jupiter.api.Test
51+
void VerifySeleniumLogging() {
52+
53+
String logFile = "TestServer/log.txt";
54+
TestData.setItem("Selenium","LogFile",logFile);
55+
56+
SeleniumDriver seleniumDriver = new SeleniumDriver(false);
57+
seleniumDriver.CloseDriver();
58+
59+
List<String> lines = new ArrayList<>();
60+
61+
try {
62+
lines = Files.readAllLines(Paths.get(logFile), Charset.defaultCharset());
63+
}
64+
catch (Exception e) {
65+
Assertions.assertEquals(true,false,"No exception reading log file");
66+
}
67+
68+
Assertions.assertEquals(true,lines.stream().filter(a -> (a.contains("[INFO]"))).count()>0,"Has more than one line with INFO");
69+
70+
71+
//Assertions.assertEquals(chromeCountBefore,chromeCountAfter-1,"Number of Chrome Driver instances increments");
72+
}
73+
74+
75+
// Verify Selenium can be launched locally with debug logging
76+
@org.junit.jupiter.api.Test
77+
void VerifySeleniumDebugLogging() {
78+
79+
String logFile = "TestServer/log.txt";
80+
TestData.setItem("Selenium","DebugMode","yes");
81+
TestData.setItem("Selenium","LogFile",logFile);
82+
83+
SeleniumDriver seleniumDriver = new SeleniumDriver(false);
84+
seleniumDriver.CloseDriver();
85+
86+
List<String> lines = new ArrayList<>();
87+
88+
try {
89+
lines = Files.readAllLines(Paths.get(logFile), Charset.defaultCharset());
90+
}
91+
catch (Exception e) {
92+
Assertions.assertEquals(true,false,"No exception reading log file");
93+
}
94+
95+
Assertions.assertEquals(true,lines.stream().filter(a -> (a.contains("[DEBUG]"))).count()>0,"Has more than one line with DEBUG");
96+
97+
98+
//Assertions.assertEquals(chromeCountBefore,chromeCountAfter-1,"Number of Chrome Driver instances increments");
99+
}
100+
101+
102+
45103
// Verify Selenium can kill other instances of Server on startup
46104
@org.junit.jupiter.api.Test
47105
void VerifySeleniumDriverCanKillPreviousInstances() {

0 commit comments

Comments
 (0)