Skip to content

Commit 6f282e0

Browse files
authored
Reference aquality.selenium.core to release version 2.0.0 (#75)
* rename BrowserManager to AqualityServices, extend it from aquality.selenium.core.applications.AqualityServices. *Change timeout in Browser from Long to Duration. * Add BrowserModule. * remove some configurations, replaced with core impl * get rid of JsonFile, migrate to JsonSettingsFile * refactor element services to use core implementations removed Logger, ElementFinder, enums, interfaces * restored logging in ElementStateProvider * Removed LocalizationManager and ConditionalWait * Removed/Replaced ElementActionRetrier * reworked configuration usage * replaced container of browser factory with instance field * add element cache configuration into json * add missed localization values * control localization values, restore some usages * refactor driver settings * Update library self-version in pom file closes #55, closes #60, closes #66, fixes #69, fixes #74
1 parent e38feda commit 6f282e0

File tree

102 files changed

+1517
-2711
lines changed

Some content is hidden

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

102 files changed

+1517
-2711
lines changed

Documentation.en.md

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The main benefits from using Aquality Selenium:
2525
- <a href='#29-access-from-the-code'>2.9. ACCESS FROM THE CODE</a>
2626
- <a href='#3-browser'>3. BROWSER</a>
2727
- <a href='#31-parallel-runs'>3.1. PARALLEL RUNS</a>
28-
- <a href='#32-browser-manager'>3.2. BROWSER MANAGER</a>
28+
- <a href='#32-aquality-services'>3.2. AQUALITY SERVICES</a>
2929
- <a href='#33-browser-factory'>3.3. BROWSER FACTORY</a>
3030
- <a href='#34-driver-capabilities'>3.4. DRIVER CAPABILITIES</a>
3131
- <a href='#35-download-directory'>3.5. DOWNLOAD DIRECTORY</a>
@@ -90,7 +90,7 @@ There are some niceties with using InternetExplorer browser. We tried to describ
9090

9191
[settings.json](./src/main/resources/settings.json) contains section `timeouts`. It includes list of timeout parameters that are used in the Aquality.
9292

93-
All parameters are used to initialise [TimeoutConfiguration](./src/main/java/aquality/selenium/configuration/TimeoutConfiguration.java) class instance. After initialising parameters can be fetched by call `Configuration.getInstance().getTimeoutConfiguration()`.
93+
All parameters are used to initialise [TimeoutConfiguration](./src/main/java/aquality/selenium/configuration/TimeoutConfiguration.java) class instance. After initialising parameters can be fetched by call `AqualityServices.getConfiguration().getTimeoutConfiguration()`.
9494

9595
Below is a description of timeouts:
9696

@@ -110,10 +110,10 @@ It is not recommended to use implicit and explicit waits together.
110110
`retry` section of [settings.json](./src/main/resources/settings.json) is responsible to configure number of attempts of manipulations with element (click, type, focus and etc.)
111111
All the operations can be executed several times if they failed at first attempt.
112112

113-
This logic is implemented in the [ElementActionRetrier](./src/main/java/aquality/selenium/utils/ElementActionRetrier.java) class. This class is used for any manipulations with elements.
113+
This logic is implemented in the [ElementActionRetrier](https://github.com/aquality-automation/aquality-selenium-core-java/blob/master/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java) class. This class is used for any manipulations with elements.
114114
`number` parameter keeps value of number of attempts. An exception will be thrown if attempts are over.
115115
`pollingInterval` keeps value of interval in **milliseconds** between attempts.
116-
[ElementActionRetrier](./src/main/java/aquality/selenium/utils/ElementActionRetrier.java) catches StaleElementReferenceException and InvalidElementStateException by default.
116+
[ElementActionRetrier](https://github.com/aquality-automation/aquality-selenium-core-java/blob/master/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java) catches StaleElementReferenceException and InvalidElementStateException by default.
117117

118118
#### 2.6. LOGGING
119119
Aquality logs operations that executes (interaction with browser, elements of the pages). Example of some log:
@@ -139,13 +139,19 @@ If parameter has value `true` user will be able to see actions more explicit (re
139139

140140
#### 2.9. ACCESS FROM THE CODE
141141

142-
Sometimes you need access to values from settings file from the code. To get it use [Configuration](./src/main/java/aquality/selenium/configuration/Configuration.java) class instance.
142+
Sometimes you need access to values from settings file from the code. To get it you can use [Configuration](./src/main/java/aquality/selenium/configuration/IConfiguration.java) class instance.
143143
Example of usage:
144144
```
145-
Configuration.getInstance().getBrowserProfile().getBrowserName()
145+
AqualityServices.getConfiguration().getBrowserProfile().getBrowserName()
146146
```
147147
returns value of parameter "browser".
148148

149+
You can also resolve the needed configuration from the AqualityServices directly:
150+
```java
151+
AqualityServices.get(IRetryConfiguration.class).getNumber(); // returns number of retry attempts for element actions, e.g. clicking.
152+
AqualityServices.getBrowserProfile(); // returns currently used set of browser settings.
153+
```
154+
149155
### **3. BROWSER**
150156

151157
Class Browser is a facade around WebDriver and provides methods to work with Browser window and WebDriver itself (for example: navigate, maximize window and etc.).
@@ -161,27 +167,32 @@ Examples of using Aquality Selenium in multi-thread mode are here [BrowserConcur
161167

162168
Test runners like TestNG, JUnit and etc. start each test in the separate thread from the box. So users do not need to do additional work if they are using such runners.
163169

164-
To use parallel streams that provided by Java from 8th version it is necessary to use BrowserManager to pass correct instance of Browser to stream function. Else parallel stream will create new Browser instances for each thread.
170+
To use parallel streams that provided by Java from 8th version it is necessary to use AqualityServices to pass correct instance of Browser to stream function. Else parallel stream will create new Browser instances for each thread.
165171
The example of usage parallel streams is here [testShouldBePossibleToUseParallelStreams](./src/test/java/tests/usecases/BrowserConcurrencyTests.java).
166172

167-
#### 3.2. BROWSER MANAGER
173+
#### 3.2. AQUALITY SERVICES
174+
Class [AqualityServices](https://github.com/aquality-automation/aquality-selenium-java/blob/Feature/Reference-aquality.selenium.core/src/main/java/aquality/selenium/browser/AqualityServices.java) provides static methods to access Browser and other utilities included in the library.
175+
176+
Usage of AqualityServices is thread-safe. Inside AqualityServices uses DI container Guice.
177+
178+
You can override any service implementation in the class extended from [BrowserModule](https://github.com/aquality-automation/aquality-selenium-java/blob/Feature/Reference-aquality.selenium.core/src/main/java/aquality/selenium/browser/BrowserModule.java), and then re-initialize AqualityServices in your code using the method ```AqualityServices.initInjector(customModule)```.
179+
Take a look at example of custom module implementation here: [BrowserFactoryTests](https://github.com/aquality-automation/aquality-selenium-java/blob/Feature/Reference-aquality.selenium.core/src/test/java/tests/usecases/BrowserFactoryTests.java)
180+
181+
#### 3.3. BROWSER FACTORY
168182

169183
There are several ways to create instance of class Browser.
170-
The main approach based on the usage of `BrowserManager` class and it's static methods. Below are options of `BrowserManager` usage.
184+
The main approach based on the usage of `AqualityServices` class and it's static methods. Below are options of `AqualityServices` usage.
171185

172186
For most cases users need to get Browser instance based on data from the settings file. To get Browser in this case use following:
173187

174188
```
175-
Browser browser = BrowserManager.getBrowser()
189+
Browser browser = AqualityServices.getBrowser()
176190
```
177191

178192
The first call of `getBrowser()` method will create instance of Browser with WebDriver inside (browser window will be opened).
179193
The next calls of `getBrowser()` in the same thread will return the same instance.
180194

181-
182-
#### 3.3. BROWSER FACTORY
183-
184-
Implicitly for users `BrowserManager` provides `Browser` through calls to browser factories.
195+
Implicitly for users `AqualityServices` provides `Browser` through calls to browser factories.
185196
Aquality Selenium implements following factories:
186197

187198
- [LocalBrowserFactory](./src/main/java/aquality/selenium/browser/LocalBrowserFactory.java) - to creating Browser on local machine (parameter `isRemote=false`)
@@ -190,19 +201,18 @@ Aquality Selenium implements following factories:
190201
Each factory implementation implements interface `IBrowserFactory` with the single method `Browser` `getBrowser()`.
191202
Users are allowed to create their on implementations if necessary.
192203

193-
To use custom factory implementation users should set it into `BrowserManager` before first call of `getBrowser()` method:
204+
To use custom factory implementation users should set it into `AqualityServices` before first call of `getBrowser()` method:
194205
```
195-
BrowserManager.setFactory(IBrowserFactory browserFactory)
206+
AqualityServices.setFactory(IBrowserFactory browserFactory)
196207
```
197208
The examples of usages custom factories can be found here [BrowserFactoryTests](./src/test/java/tests/usecases/BrowserFactoryTests.java)
198209

199-
If there are reasons to not to use factories user is able to create Browser instance using constructor and then put it into BrowserManager:
210+
If there are reasons to not to use factories user is able to create Browser instance using constructor and then put it into AqualityServices:
200211
```
201-
BrowserManager.setBrowser(Browser browser)
212+
AqualityServices.setBrowser(Browser browser)
202213
```
203214

204-
Browser class has public constructor with the signature: `Browser(RemoteWebDriver remoteWebDriver, IСonfiguration configuration)`.
205-
User should implement his own implementation of `IConfiguration` - but existing IConfiguration implementation can be used, inherited, used partially(`IDriverSettings`, `ITimeoutConfiguration` and etc.)
215+
Browser class has public constructor with the signature: `Browser(RemoteWebDriver remoteWebDriver)`. Other needed services are resolved from the DI container. For example, user could implement his own implementation of `IConfiguration` - but existing IConfiguration implementation can be used, inherited, used partially(`IDriverSettings`, `ITimeoutConfiguration` and etc.)
206216

207217
#### 3.4. DRIVER CAPABILITIES
208218

@@ -242,7 +252,7 @@ But there are no restrictions to add your own implementation.
242252
`Browser` class provides methods to work with alerts and prompts dialogs:
243253

244254
```
245-
BrowserManager.getBrowser().handleAlert(AlertActions.ACCEPT);
255+
AqualityServices.getBrowser().handleAlert(AlertActions.ACCEPT);
246256
```
247257

248258
More examples here: [AlertTests.java](./src/test/java/tests/integration/AlertTests.java).
@@ -251,7 +261,7 @@ More examples here: [AlertTests.java](./src/test/java/tests/integration/AlertTes
251261

252262
To take a screenshot of the page there is the method:
253263
```
254-
BrowserManager.getBrowser().getScreenshot()
264+
AqualityServices.getBrowser().getScreenshot()
255265
```
256266

257267
Example of taking screenshots here: [testShouldBePossibleToMakeScreenshot](./src/test/java/tests/integration/BrowserTests.java)
@@ -266,7 +276,7 @@ When Browser instantiated and navigation to necessary page is done user can begi
266276
Below is an example of getting ITextBox element:
267277

268278
```
269-
ElementFactory elementFactory = new ElementFactory();
279+
IElementFactory elementFactory = AqualityServices.getElementFactory();
270280
ITextBox txbUsername = elementFactory.getTextBox(By.id("username"), "Username");
271281
```
272282
`ElementFactory` is able to build elements of any types that implements `IElement` interface.
@@ -275,7 +285,7 @@ ITextBox txbUsername = elementFactory.getTextBox(By.id("username"), "Username");
275285
#### 4.2. CUSTOM ELEMENTS
276286

277287
User has abilities to create his own type of element by implementing interface or using inheritance.
278-
For this goal `ElementFactory` provides method \&lt;T extends IElement\&gt; T getCustomElement.
288+
For this goal `ElementFactory` provides method `<T extends IElement> T getCustomElement`.
279289
Example of creating custom element here [CustomElementTests](./src/test/java/tests/usecases/CustomElementTests.java).
280290

281291
#### 4.3. LIST OF ELEMENTS
@@ -340,16 +350,21 @@ There are several overrided methods that takes scripts as String, File or JavaSc
340350

341351
### **7. JSON FILE**
342352

343-
Aquality Selenium uses [JsonFile](./src/main/java/aquality/selenium/utils/JsonFile.java) class to process the JSON files.
353+
Aquality Selenium uses [JsonSettingsFile](https://github.com/aquality-automation/aquality-selenium-core-java/blob/master/src/main/java/aquality/selenium/core/utilities/JsonSettingsFile.java) class to process the JSON files.
344354
Users can use this class to process JSON files from their own project.
345355
For example, if user wants to keep URL to web site that is automating he can put this URL in some JSON file and read value with mentioned class:
346356
```
347-
JsonFile environment = new JsonFile("settings.json")
357+
ISettingsFile environment = new JsonSettingsFile("settings.json")
348358
String url = environment.getValue("/url").toString();
349359
```
350360
### **8. CONDITIONAL WAIT**
351361

352-
If you need to wait for any condition to be met, you can use the [ConditionalWait](./src/main/java/aquality/selenium/waitings/ConditionalWait.java) class provided by Aquality Selenium.
362+
If you need to wait for any condition to be met, you can use the [ConditionalWait](https://github.com/aquality-automation/aquality-selenium-core-java/blob/master/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java) class provided by Aquality Selenium.
363+
```java
364+
File fileDownloaded = new File(downloadDirInitialized + fileName);
365+
AqualityServices.getConditionalWait().waitForTrue(() -> fileDownloaded.exists(),
366+
Duration.ofSeconds(120), Duration.ofMillis(300), "File should be downloaded");
367+
```
353368
All class methods wait for the condition to be met, but return values and handle exceptions ​​differently:
354369
1. ```waitForTrue``` - throws an exception if the condition is not met, returns nothing.
355370
2. ```boolean waitFor``` - returns true if the condition is fulfilled or false otherwise. Method does not throw any exception.

0 commit comments

Comments
 (0)