Skip to content

Commit 7d224dd

Browse files
committed
Merge branch 'master' into Feature/Add-Multichoice-Combobox
# Conflicts: # src/main/resources/localization/be.json # src/main/resources/localization/en.json # src/main/resources/localization/ru.json
2 parents 96d1c97 + 36f3c4b commit 7d224dd

File tree

112 files changed

+5075
-516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+5075
-516
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Compiled class file
2-
*.class
1+
# Build results
2+
target
3+
downloads
34

45
# Log file
56
*.log
67

8+
# Visualization files
9+
visualDumps/
10+
711
# BlueJ files
812
*.ctxt
913

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2019 Aquality Automation
189+
Copyright 2023 Aquality Automation
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ Most of performed methods are logged using LOG4J, so you can easily see a histor
1313
We use interfaces where is possible, so you can implement your own version of target interface with no need to rewrite other classes.
1414

1515
### Quick start
16+
To start the project using aquality.selenium framework, you can [download our template BDD project by this link.](https://github.com/aquality-automation/aquality-selenium-java-template)
1617

17-
1. To start work with this package, simply add the dependency to your pom.xml:
18+
Alternatively, you can follow the steps below:
19+
20+
1. Add the dependency to your pom.xml:
1821
```
1922
<dependency>
2023
<groupId>com.github.aquality-automation</groupId>
2124
<artifactId>aquality-selenium</artifactId>
22-
<version>LATEST</version>
25+
<version>4.x.x</version>
2326
</dependency>
2427
```
2528

@@ -47,14 +50,37 @@ txbSearch.submit();
4750
browser.waitForPageToLoad();
4851
```
4952

50-
6. Quit browser at the end
53+
6. Use BiDi functionality to handle basic authentication:
54+
```java
55+
browser.network().addBasicAuthentication("domain.com", "username", "password");
5156
```
57+
or intercept network requests/responses:
58+
```java
59+
browser.network().startNetworkInterceptor((HttpHandler) request -> new HttpResponse()
60+
.setStatus(HttpStatus.SC_OK)
61+
.addHeader("Content-Type", MediaType.HTML_UTF_8.toString())
62+
.setContent(utf8String("Some phrase")));
63+
```
64+
7. Emulate GeoLocation, Device, Touch, Media, UserAgent overrides, Disable script execution, log HTTP exchange, track Performance metrics, add initialization scripts, and more using browser.devTools() interfaces:
65+
```java
66+
final double latitude = 53.90772672521578;
67+
final double longitude = 27.458060411865375;
68+
final double accuracy = 0.97;
69+
browser.devTools().emulation().setGeolocationOverride(latitude, longitude, accuracy);
70+
```
71+
See more DevTools use cases [here](./src/test/java/tests/usecases/devtools)
72+
73+
8. Quit browser at the end
74+
```java
5275
browser.quit();
5376
```
5477

55-
See full example [here](./src/test/java/tests/usecases/QuickStartExample.java)
78+
See quick start example [here](./src/test/java/tests/usecases/QuickStartExample.java)
5679

5780
### Documentation
5881
To get more details please look at documentation:
5982
- [In English](https://github.com/aquality-automation/aquality-selenium-java/wiki/Overview-(English))
6083
- [In Russian](https://github.com/aquality-automation/aquality-selenium-java/wiki/Overview-(Russian))
84+
85+
### License
86+
Library's source code is made available under the [Apache 2.0 license](LICENSE).

pom.xml

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.aquality-automation</groupId>
88
<artifactId>aquality-selenium</artifactId>
9-
<version>2.5.2</version>
9+
<version>4.0.0</version>
1010
<packaging>jar</packaging>
1111
<name>Aquality Selenium</name>
1212
<description>Library around Selenium WebDriver</description>
@@ -67,55 +67,39 @@
6767
<id>knysh</id>
6868
<name>Sergey Knysh</name>
6969
</developer>
70+
<developer>
71+
<id>d2kravchenko</id>
72+
<name>Dmitry Kravchenko</name>
73+
</developer>
74+
<developer>
75+
<id>aPavar</id>
76+
<name>Andrey Pavar</name>
77+
</developer>
7078
</developers>
7179

7280
<dependencies>
7381
<dependency>
7482
<groupId>com.github.aquality-automation</groupId>
7583
<artifactId>aquality-selenium-core</artifactId>
76-
<version>1.2.0</version>
77-
</dependency>
78-
79-
<dependency>
80-
<groupId>org.seleniumhq.selenium</groupId>
81-
<artifactId>selenium-java</artifactId>
82-
<version>3.141.59</version>
84+
<version>3.0.0</version>
8385
</dependency>
8486

8587
<dependency>
8688
<groupId>io.github.bonigarcia</groupId>
8789
<artifactId>webdrivermanager</artifactId>
88-
<version>4.2.0</version>
90+
<version>5.3.2</version>
8991
</dependency>
9092

9193
<dependency>
9294
<groupId>com.fasterxml.jackson.core</groupId>
9395
<artifactId>jackson-databind</artifactId>
94-
<version>2.9.9</version>
96+
<version>2.14.2</version>
9597
</dependency>
9698

9799
<dependency>
98100
<groupId>org.testng</groupId>
99101
<artifactId>testng</artifactId>
100-
<version>6.14.3</version>
101-
<scope>test</scope>
102-
</dependency>
103-
<dependency>
104-
<groupId>log4j</groupId>
105-
<artifactId>log4j</artifactId>
106-
<version>1.2.17</version>
107-
</dependency>
108-
109-
<dependency>
110-
<groupId>org.slf4j</groupId>
111-
<artifactId>slf4j-api</artifactId>
112-
<version>1.7.26</version>
113-
</dependency>
114-
115-
<dependency>
116-
<groupId>org.slf4j</groupId>
117-
<artifactId>slf4j-log4j12</artifactId>
118-
<version>1.7.26</version>
102+
<version>7.5</version>
119103
<scope>test</scope>
120104
</dependency>
121105
</dependencies>
@@ -239,4 +223,4 @@
239223
</plugin>
240224
</plugins>
241225
</build>
242-
</project>
226+
</project>

src/main/java/aquality/selenium/browser/Browser.java

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package aquality.selenium.browser;
22

3+
import aquality.selenium.browser.devtools.DevToolsHandling;
4+
import aquality.selenium.browser.devtools.JavaScriptHandling;
5+
import aquality.selenium.browser.devtools.NetworkHandling;
36
import aquality.selenium.configuration.IBrowserProfile;
47
import aquality.selenium.configuration.ITimeoutConfiguration;
58
import aquality.selenium.core.applications.IApplication;
69
import aquality.selenium.core.localization.ILocalizationManager;
710
import aquality.selenium.core.localization.ILocalizedLogger;
811
import aquality.selenium.core.waitings.IConditionalWait;
912
import org.apache.commons.io.IOUtils;
10-
import org.openqa.selenium.Alert;
11-
import org.openqa.selenium.Dimension;
12-
import org.openqa.selenium.NoAlertPresentException;
13-
import org.openqa.selenium.OutputType;
13+
import org.apache.commons.lang3.NotImplementedException;
14+
import org.openqa.selenium.*;
1415
import org.openqa.selenium.WebDriver.Navigation;
16+
import org.openqa.selenium.devtools.HasDevTools;
1517
import org.openqa.selenium.logging.LogEntries;
18+
import org.openqa.selenium.remote.Augmenter;
1619
import org.openqa.selenium.remote.RemoteWebDriver;
1720
import org.openqa.selenium.support.ui.ExpectedCondition;
1821

1922
import java.io.File;
2023
import java.io.IOException;
2124
import java.nio.charset.StandardCharsets;
2225
import java.time.Duration;
23-
import java.util.concurrent.TimeUnit;
2426
import java.util.function.Supplier;
2527

2628
public class Browser implements IApplication {
@@ -32,6 +34,7 @@ public class Browser implements IApplication {
3234
private final ILocalizationManager localizationManager;
3335
private final ILocalizedLogger localizedLogger;
3436

37+
private DevToolsHandling devTools;
3538
private Duration implicitTimeout;
3639

3740
public Browser(RemoteWebDriver remoteWebDriver) {
@@ -42,7 +45,7 @@ public Browser(RemoteWebDriver remoteWebDriver) {
4245
this.timeouts = AqualityServices.get(ITimeoutConfiguration.class);
4346
webDriver = remoteWebDriver;
4447
this.implicitTimeout = timeouts.getImplicit();
45-
getDriver().manage().timeouts().implicitlyWait(implicitTimeout.getSeconds(), TimeUnit.SECONDS);
48+
getDriver().manage().timeouts().implicitlyWait(implicitTimeout);
4649
setPageLoadTimeout(timeouts.getPageLoad());
4750
setScriptTimeout(timeouts.getScript());
4851
}
@@ -151,7 +154,7 @@ public IBrowserTabNavigation tabs() {
151154
public void setPageLoadTimeout(Duration timeout) {
152155
if (!getBrowserName().equals(BrowserName.SAFARI)) {
153156
localizedLogger.debug("loc.browser.page.load.timeout", timeout.getSeconds());
154-
getDriver().manage().timeouts().pageLoadTimeout(timeout.getSeconds(), TimeUnit.SECONDS);
157+
getDriver().manage().timeouts().pageLoadTimeout(timeout);
155158
}
156159
}
157160

@@ -164,7 +167,7 @@ public void setPageLoadTimeout(Duration timeout) {
164167
public void setImplicitWaitTimeout(Duration timeout) {
165168
if (!timeout.equals(getImplicitWaitTimeout())) {
166169
localizedLogger.debug("loc.browser.implicit.timeout", timeout.getSeconds());
167-
getDriver().manage().timeouts().implicitlyWait(timeout.getSeconds(), TimeUnit.SECONDS);
170+
getDriver().manage().timeouts().implicitlyWait(timeout);
168171
implicitTimeout = timeout;
169172
}
170173
}
@@ -176,7 +179,7 @@ public void setImplicitWaitTimeout(Duration timeout) {
176179
*/
177180
public void setScriptTimeout(Duration timeout) {
178181
localizedLogger.debug("loc.browser.script.timeout", timeout.getSeconds());
179-
getDriver().manage().timeouts().setScriptTimeout(timeout.getSeconds(), TimeUnit.SECONDS);
182+
getDriver().manage().timeouts().scriptTimeout(timeout);
180183
}
181184

182185
/**
@@ -262,6 +265,17 @@ public Object executeScript(final String script, Object... arguments) {
262265
return executeJavaScript(() -> getDriver().executeScript(script, arguments));
263266
}
264267

268+
/**
269+
* Executes JS (jQuery) script.
270+
*
271+
* @param script Script pinned with {@link Browser#javaScriptEngine()}.
272+
* @param arguments Arguments for the script (web elements, values etc.
273+
* @return Result object of script execution
274+
*/
275+
public Object executeScript(final ScriptKey script, Object... arguments) {
276+
return executeJavaScript(() -> getDriver().executeScript(script, arguments));
277+
}
278+
265279
private Object executeJavaScript(Supplier<Object> executeScriptFunc) {
266280
Object result = executeScriptFunc.get();
267281
return result instanceof Boolean ? Boolean.parseBoolean(result.toString()) : result;
@@ -368,4 +382,41 @@ public final BrowserName getBrowserName() {
368382
private Duration getImplicitWaitTimeout() {
369383
return implicitTimeout;
370384
}
385+
386+
/**
387+
* Provides interface to handle DevTools for Chromium-based and Firefox drivers.
388+
* @return an instance of {@link DevToolsHandling}
389+
*/
390+
public DevToolsHandling devTools() {
391+
if (devTools != null) {
392+
return devTools;
393+
}
394+
WebDriver driver = getDriver();
395+
if (!(driver instanceof HasDevTools)) {
396+
driver = new Augmenter().augment(driver);
397+
}
398+
if (driver instanceof HasDevTools) {
399+
devTools = new DevToolsHandling((HasDevTools) driver);
400+
return devTools;
401+
}
402+
else {
403+
throw new NotImplementedException("DevTools protocol is not supported for current browser.");
404+
}
405+
}
406+
407+
/**
408+
* Provides Network Handling functionality
409+
* @return an instance of {@link NetworkHandling}
410+
*/
411+
public NetworkHandling network() {
412+
return devTools().network();
413+
}
414+
415+
/**
416+
* Provides JavaScript Monitoring functionality.
417+
* @return an instance of {@link JavaScriptHandling}
418+
*/
419+
public JavaScriptHandling javaScriptEngine() {
420+
return devTools().javaScript();
421+
}
371422
}

src/main/java/aquality/selenium/browser/BrowserName.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ public enum BrowserName {
55
EDGE,
66
FIREFOX,
77
IEXPLORER,
8-
SAFARI
8+
OPERA,
9+
OTHER,
10+
SAFARI,
11+
YANDEX
912
}

src/main/java/aquality/selenium/browser/JavaScript.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ public enum JavaScript {
3333
SELECT_COMBOBOX_VALUE_BY_TEXT("selectComboboxValueByText.js"),
3434
SET_FOCUS("setFocus.js"),
3535
SET_VALUE("setValue.js"),
36+
SET_ATTRIBUTE("setAttribute.js"),
3637
SCROLL_BY("scrollBy.js"),
3738
IS_PAGE_LOADED("isPageLoaded.js"),
3839
SCROLL_WINDOW_BY("scrollWindowBy.js"),
3940
SET_INNER_HTML("setInnerHTML.js"),
4041
GET_VIEWPORT_COORDINATES("getViewPortCoordinates.js"),
4142
GET_SCREEN_OFFSET("getScreenOffset.js"),
4243
OPEN_IN_NEW_TAB("openInNewTab.js"),
43-
OPEN_NEW_TAB("openNewTab.js");
44+
OPEN_NEW_TAB("openNewTab.js"),
45+
EXPAND_SHADOW_ROOT("expandShadowRoot.js");
4446

4547
private final String filename;
4648

@@ -55,11 +57,12 @@ public enum JavaScript {
5557
*/
5658
public String getScript() {
5759
URL scriptFile = getClass().getResource("/js/" + filename);
58-
try {
59-
InputStream stream = scriptFile.openStream();
60-
return IOUtils.toString(stream, StandardCharsets.UTF_8.name());
61-
} catch (IOException e) {
62-
Logger.getInstance().fatal(format("Couldn't find the script \"%s\"", filename), e);
60+
if (scriptFile != null) {
61+
try (InputStream stream = scriptFile.openStream()) {
62+
return IOUtils.toString(stream, StandardCharsets.UTF_8.name());
63+
} catch (IOException e) {
64+
Logger.getInstance().fatal(format("Couldn't find the script \"%s\"", filename), e);
65+
}
6366
}
6467
return "";
6568
}

0 commit comments

Comments
 (0)