Skip to content

Commit 0738429

Browse files
committed
selenium upgrade
1 parent fae2faf commit 0738429

File tree

6 files changed

+32
-44
lines changed

6 files changed

+32
-44
lines changed

java/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>org.seleniumhq.selenium</groupId>
5454
<artifactId>selenium-java</artifactId>
55-
<version>3.141.59</version>
55+
<version>4.3.0</version>
5656
<exclusions>
5757
<exclusion>
5858
<groupId>org.hamcrest</groupId>
@@ -95,8 +95,8 @@
9595
<artifactId>maven-compiler-plugin</artifactId>
9696
<configuration>
9797
<mavenExecutorId>forked-path</mavenExecutorId>
98-
<source>1.7</source>
99-
<target>1.7</target>
98+
<source>1.8</source>
99+
<target>1.8</target>
100100
</configuration>
101101
</plugin>
102102
<plugin>

java/src/main/java/org/seleniumhq/selenium/fluent/FluentBy.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515
limitations under the License.
1616
*/
1717

18-
import org.openqa.selenium.By;
19-
import org.openqa.selenium.InvalidSelectorException;
20-
import org.openqa.selenium.SearchContext;
21-
import org.openqa.selenium.WebDriver;
22-
import org.openqa.selenium.WebElement;
23-
import org.openqa.selenium.internal.FindsByClassName;
24-
import org.openqa.selenium.internal.FindsByXPath;
25-
26-
import java.lang.Override;
27-
import java.lang.String;
18+
import org.openqa.selenium.*;
19+
2820
import java.util.List;
2921

3022
import static java.util.Arrays.asList;
@@ -225,18 +217,14 @@ public ByStrictClassName(String className) {
225217

226218
@Override
227219
public List<WebElement> findElements(SearchContext context) {
228-
if (context instanceof FindsByClassName)
229-
return ((FindsByClassName) context).findElementsByClassName(className);
230-
return ((FindsByXPath) context).findElementsByXPath(".//*["
231-
+ "@class = '" + className + "']");
220+
return context.findElements(By.className(className));
221+
// return context.findElements(By.xpath(".//*["
222+
// + "@class = '" + className + "']"));
232223
}
233224

234225
@Override
235226
public WebElement findElement(SearchContext context) {
236-
if (context instanceof FindsByClassName)
237-
return ((FindsByClassName) context).findElementByClassName(className);
238-
return ((FindsByXPath) context).findElementByXPath(".//*["
239-
+ "@class = '" + className + "']");
227+
return context.findElement(By.className(className));
240228
}
241229

242230
@Override

java/src/main/java/org/seleniumhq/selenium/fluent/monitors/ScreenShotOnError.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.io.File;
1111
import java.io.IOException;
1212
import java.nio.file.Files;
13-
import java.nio.file.Path;
1413

1514
public class ScreenShotOnError extends Monitor.NULL {
1615

@@ -63,7 +62,9 @@ public String getContext() {
6362
if (elemClassName.startsWith("org.junit.runners") || elemClassName.startsWith("org.testng.internal")) {
6463
return lastNonReflectionElem.getClassName() + "." + lastNonReflectionElem.getMethodName();
6564
}
66-
if (!elemClassName.startsWith("sun.reflect.") && !elemClassName.startsWith("java.lang.reflect")) {
65+
if (!elemClassName.startsWith("sun.reflect.")
66+
&& !elemClassName.startsWith("java.lang.reflect")
67+
&& !elemClassName.startsWith("jdk.internal.reflect")) {
6768
lastNonReflectionElem = elem;
6869
}
6970

java/src/test/java/org/seleniumhq/selenium/fluent/FluentByTest.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
import org.openqa.selenium.By;
66
import org.openqa.selenium.SearchContext;
77
import org.openqa.selenium.WebElement;
8-
import org.openqa.selenium.internal.FindsByXPath;
98

109
import java.lang.reflect.Field;
1110
import java.util.List;
1211

1312
import static com.google.common.collect.Lists.newArrayList;
1413
import static org.hamcrest.MatcherAssert.assertThat;
1514
import static org.hamcrest.core.Is.is;
16-
import static org.mockito.Mockito.mock;
17-
import static org.mockito.Mockito.when;
15+
import static org.mockito.Mockito.*;
1816

1917
public class FluentByTest {
2018

@@ -33,7 +31,7 @@ public void attribute() throws IllegalAccessException {
3331

3432
FindsByXPathSearchContext context = mock(FindsByXPathSearchContext.class);
3533
WebElement we = mock(WebElement.class);
36-
when(context.findElementByXPath(".//*[@foo = 'bar']")).thenReturn(we);
34+
when(context.findElement(By.xpath(".//*[@foo = 'bar']"))).thenReturn(we);
3735
WebElement bar = fooBar.findElement(context);
3836
assertThat(bar, is(we));
3937

@@ -42,7 +40,7 @@ public void attribute() throws IllegalAccessException {
4240
By lastFooBar = FluentBy.last(fooBar);
4341
assertThat(lastFooBar.toString(), is("FluentBy.last(FluentBy.attribute: foo = 'bar')"));
4442

45-
when(context.findElementByXPath(".//*[@foo = 'bar' and position() = last()]")).thenReturn(we);
43+
when(context.findElement(By.xpath(".//*[@foo = 'bar' and position() = last()]"))).thenReturn(we);
4644
WebElement lastBar = fooBar.findElement(context);
4745
assertThat(lastBar, is(we));
4846
}
@@ -55,7 +53,7 @@ public void not_attribute() throws IllegalAccessException {
5553

5654
FindsByXPathSearchContext context = mock(FindsByXPathSearchContext.class);
5755
WebElement we = mock(WebElement.class);
58-
when(context.findElementByXPath(".//*[not(@foo)]")).thenReturn(we);
56+
when(context.findElement(By.xpath(".//*[not(@foo)]"))).thenReturn(we);
5957
WebElement bar = notFoo.findElement(context);
6058

6159
assertThat(bar, is(we));
@@ -65,7 +63,7 @@ public void not_attribute() throws IllegalAccessException {
6563
By lastFooBar = FluentBy.last(notFoo);
6664
assertThat(lastFooBar.toString(), is("FluentBy.last(FluentBy.notAttribute: foo)"));
6765

68-
when(context.findElementByXPath(".//*[@foo = 'bar' and position() = last()]")).thenReturn(we);
66+
when(context.findElement(By.xpath(".//*[@foo = 'bar' and position() = last()]"))).thenReturn(we);
6967
WebElement lastBar = notFoo.findElement(context);
7068
assertThat(lastBar, is(we));
7169
}
@@ -79,11 +77,11 @@ public void attribute_without_value() throws IllegalAccessException {
7977
WebElement we = mock(WebElement.class);
8078
WebElement we2 = mock(WebElement.class);
8179

82-
when(context.findElementByXPath(".//*[@foo]")).thenReturn(we);
80+
when(context.findElement(By.xpath(".//*[@foo]"))).thenReturn(we);
8381
WebElement bar = fooBar.findElement(context);
8482
assertThat(bar, is(we));
8583

86-
when(context.findElementsByXPath(".//*[@foo]")).thenReturn(newArrayList(we, we2));
84+
when(context.findElements(By.xpath(".//*[@foo]"))).thenReturn(newArrayList(we, we2));
8785
List<WebElement> bars = fooBar.findElements(context);
8886
assertThat(bars.get(0), is(we));
8987

@@ -97,7 +95,7 @@ public void last() throws IllegalAccessException {
9795
By lastFooBar = FluentBy.last();
9896
assertThat(lastFooBar.toString(), is("FluentBy.last()"));
9997

100-
when(context.findElementByXPath(".//*[position() = last()]")).thenReturn(we);
98+
when(context.findElement(By.xpath(".//*[position() = last()]"))).thenReturn(we);
10199
WebElement lastBar = lastFooBar.findElement(context);
102100
assertThat(lastBar, is(we));
103101
}
@@ -111,12 +109,13 @@ public void strict_class_name() throws IllegalAccessException {
111109
By scn = FluentBy.strictClassName("blort");
112110
assertThat(scn.toString(), is("FluentBy.strictClassName: blort"));
113111

114-
when(context.findElementByXPath(".//*[@class = 'blort']")).thenReturn(we);
112+
when(context.findElement(By.className("blort"))).thenReturn(we);
115113
WebElement blort = scn.findElement(context);
116114
assertThat(blort, is(we));
117115

118-
when(context.findElementsByXPath(".//*[@class = 'blort']")).thenReturn(newArrayList(we, we2));
116+
when(context.findElements(By.className("blort"))).thenReturn(newArrayList(we, we2));
119117
List<WebElement> blorts = scn.findElements(context);
118+
//verifyNoMoreInteractions(we,we2, context);
120119
assertThat(blorts.get(0), is(we));
121120

122121
}
@@ -130,11 +129,11 @@ public void composite_classname() throws IllegalAccessException {
130129
By aB = FluentBy.composite(new By.ByTagName("a"), new By.ByClassName("b"));
131130
assertThat(aB.toString(), is("FluentBy.composite([By.tagName: a, By.className: b])"));
132131

133-
when(context.findElementByXPath(".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]")).thenReturn(we);
132+
when(context.findElement(By.xpath(".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]"))).thenReturn(we);
134133
WebElement blort = aB.findElement(context);
135134
assertThat(blort, is(we));
136135

137-
when(context.findElementsByXPath(".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]")).thenReturn(newArrayList(we, we2));
136+
when(context.findElements(By.xpath(".//a[contains(concat(' ',normalize-space(@class),' '),' b ')]"))).thenReturn(newArrayList(we, we2));
138137
List<WebElement> blorts = aB.findElements(context);
139138
assertThat(blorts.get(0), is(we));
140139
}
@@ -148,17 +147,17 @@ public void composite_attribute() throws IllegalAccessException {
148147
By aB = FluentBy.composite(new By.ByTagName("a"), new FluentBy.ByAttribute("b", null));
149148
assertThat(aB.toString(), is("FluentBy.composite([By.tagName: a, FluentBy.attribute: b])"));
150149

151-
when(context.findElementByXPath(".//a[@b]")).thenReturn(we);
150+
when(context.findElement(By.xpath(".//a[@b]"))).thenReturn(we);
152151
WebElement blort = aB.findElement(context);
153152
//verifyNoMoreInteractions(context);
154153
assertThat(blort, is(we));
155154

156-
when(context.findElementsByXPath(".//a[@b]")).thenReturn(newArrayList(we, we2));
155+
when(context.findElements(By.xpath(".//a[@b]"))).thenReturn(newArrayList(we, we2));
157156
List<WebElement> blorts = aB.findElements(context);
158157
assertThat(blorts.get(0), is(we));
159158

160159
}
161160

162-
private static interface FindsByXPathSearchContext extends FindsByXPath, SearchContext {
161+
private static interface FindsByXPathSearchContext extends SearchContext {
163162
}
164163
}

java/src/test/java/org/seleniumhq/selenium/fluent/StaleRecoveringTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ private static class FirstGetAttributeIsStaleDriver extends ChromeDriver {
8686
public final boolean[] staleElementThrown = {false};
8787

8888
@Override
89-
public WebElement findElementById(String using) {
90-
final WebElement we = super.findElementById(using);
89+
public WebElement findElement(By by) {
90+
final WebElement we = super.findElement(by);
9191
return new WebElement() {
9292
public void click() {
9393
we.click();

java/src/test/java/org/seleniumhq/selenium/fluent/elements/select.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void method_on_select_is_invoked() {
6464
when(wd.findElement(By.tagName("select"))).thenReturn(we);
6565
when(we.getTagName()).thenReturn("select");
6666
when(we.getTagName()).thenReturn("select");
67-
when(we.getAttribute("multiple")).thenReturn("true");
67+
when(we.getDomAttribute("multiple")).thenReturn("true");
6868
when(we.findElements(By.xpath(".//option[@value = \"bar\"]"))).thenReturn(newArrayList(we2, we3));
6969
when(we2.isSelected()).thenReturn(true);
7070
when(we3.isSelected()).thenReturn(false);
@@ -75,7 +75,7 @@ public void method_on_select_is_invoked() {
7575

7676
verify(wd).findElement(By.tagName("select"));
7777
verify(we, times(2)).getTagName();
78-
verify(we).getAttribute("multiple");
78+
verify(we).getDomAttribute("multiple");
7979
verify(we).findElements(By.xpath(".//option[@value = \"bar\"]"));
8080
verify(we2).isSelected();
8181
verify(we3).isSelected();

0 commit comments

Comments
 (0)