You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package is a library designed to simplify your work with Selenium WebDriver.<br>
5
-
You've got to use this set of methods, related to most common actions performed with web elements. <br>
6
-
Most of performed methods are logged using LOG4J, so you can easily see a history of performed actions in your log.<br>
7
-
We use interfaces where is possible, so you can implement your own version of target interface with no need to rewrite other classes.<br>
8
-
The solution constructed to be used with PageObjects pattern, but it is not necessary requirement. You can read more about PageObjects approach on various sources, e.g. here: http://www.assertselenium.com/automation-design-practices/page-object-pattern/
9
-
<br>
10
-
To start work with this package, simply add the dependency to your pom.xml:
3
+
This package is a library designed to simplify your work with Selenium WebDriver.
4
+
5
+
You've got to use this set of methods, related to most common actions performed with web elements.
6
+
7
+
Most of performed methods are logged using LOG4J, so you can easily see a history of performed actions in your log.
8
+
9
+
We use interfaces where is possible, so you can implement your own version of target interface with no need to rewrite other classes.
10
+
11
+
### Quick start
12
+
13
+
1. To start work with this package, simply add the dependency to your pom.xml:
11
14
```
12
15
<dependency>
13
16
<groupId>aquality-automation</groupId>
@@ -16,263 +19,36 @@ To start work with this package, simply add the dependency to your pom.xml:
16
19
</dependency>
17
20
```
18
21
19
-
## How to use:
20
-
You can take a look at our integration test "ShoppingCartTest" and related classes as an example of typical usage of the package.<br>
21
-
Step-by-step guide:<br>
22
-
1) Get instance of Browser:
23
-
```java
24
-
Browser browser =Browser.getInstance();
25
-
```
26
-
Use Browser's methods directly for general actions, such as navigation, window resize, scrolling and alerts handling:
3) Add elements you want to interact within the current form as private final fields. UsegetElementFactory() methods to get an instance of each element.
-As you can see, an instance of ElementFactory is created for each form inherited from Form; you can create your own instance of ElementFactory whether you need it; you can extend ElementFactory classfor your purposes, e.g. for your custom elements.
56
-
57
-
If an element have locator dependent on parameter, you can store locator template as string (See javadocs <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)">String.format(String format, Object... args)</a>) in private constant at form class.
22
+
2. Add configuration file [settings.json](./src/main/resources/settings.json) to resources folder (usually `src/test/resources`)
## Use several browser instances in parallel (multithreading):
103
-
In our library instances of some core classes (Browser, BrowserFactoryHolder, Logger, Configuration) are stored in thread-local containers.
104
-
You may want to interact with more than one instance of Browser. For this purpose, you will need to create browser instances in separate threads, to make sure that their work does not interrupt each other.<br>
105
-
You can take a look at our test class BrowserConcurrencyTests for example:
36
+
5. Add elements you want to interact within the current form as private final fields. Use ElementFactory class's methods to get an instance of each element.
106
37
```java
107
-
import aquality.selenium.browser.Browser;
108
-
import org.testng.Assert;
109
-
import org.testng.annotations.Test;
110
-
import theinternet.TheInternetPage;
111
-
112
-
public class BrowserConcurrencyTests {
113
-
114
-
@Test
115
-
public void testBrowserShouldBePossibleToHaveTwoBrowsersForTwoThreads() throws InterruptedException {
116
-
117
-
Thread thread01 = new Thread(new BrowserThread(TheInternetPage.CHECKBOXES.getAddress()));
118
-
Thread thread02 = new Thread(new BrowserThread(TheInternetPage.LOGIN.getAddress()));
- **browser**: the package with classes and methods to setup and interract with browser
147
-
- **factory**: the package related to browser setup
148
-
*BrowserFactoryHolder* allows you to setup a browser instance. <br>
149
-
It is implemented using [WebDriverManager](https://github.com/bonigarcia/webdrivermanager). This manager allows us to get required version of target browser's webdriver.
150
-
-In the package we have an interface *IBrowserFactory* and two default implementations:LocalBrowserFactory and RemoteBrowserFactory*.
151
-
- Static method *BrowserFactoryHolder.getFactory()* returns you one of these implementations basing on current configuration's property browser.remote in config.properties.
152
-
It is used in *Browser* class.
153
-
- If you need to specify a concrete version of WebDriver to be used, you can implement your own implementation of *IBrowserFactory*. Please use static method *BrowserFactoryHolder.setFactory(IBrowserFactorywebDriverFactory)* so set usage of your implementation.
154
-
- *Browser* is a wrapper to interact with WebDriver. It contains the most common methods to interact with browser: setup, navigate, resize, scroll, handle alerts etc.
155
-
- **configuration**: package to read configuration from .properties and .json files. Please see <a href='#configuration'>Configuration</a> section for detailed desctiption.
156
-
- **elements**: package with functionality designed to simplify work with webelements
157
-
- **actions** functionality related to javascript and mouse actions performed under webelements
158
-
- **interfaces** common interfaces to easily interact with webelements via specific wrappers: *IButton, ICheckBox, IComboBox, ILabel, ILink, IRadioButton* and *ITextBox*.
159
-
- *ElementFactory*: class designed to create instances of element wrappers
160
-
You can implement your own type of element by extending *Element* class. If you prefer to create your own interface, it should implement *IElement* interface.
161
-
- **forms**: contains *Form* class and related *PageInfo* annotation
162
-
- **logger**: contains Logger designed to log performed actions
163
-
- **waitings**: contains ConditionalWait class with functionality for conditional waitings.
164
-
- **resources**
165
-
- **js**: javascript functions used within this package
166
-
167
-
## Configuration
168
-
We store configuration parameters in resource files.<br>
169
-
You can find default configuration files inside the library in the resources folder <br>
170
-
To change some parameter, you will need to add related resource file into your project and change the required parameter.<br>
171
-
Make sure to add it to the same path where it is presented in library.<br>
172
-
Alternatively, you can override some class from the ``` package aquality.selenium.configuration; ```
173
-
174
-
#### Configuration resources structure
175
-
-**resourses**
176
-
-**selenium.configuration**: local and remote browser configuration files: capabilities, options, start arguments and timeout properties
-**localization**: messages and templates used for logging in specific language
186
-
- en.properties
187
-
- ru.properties
188
-
-**loglang.properties** logging language. default value is "EN"-this means that en.properties will be used. You can add your own language if needed.
189
-
-**<a href='#configproperties'>config.properties</a>**: general browser settings, such as browser.remote and element.highlight
190
-
-**log4j.properties**:default log4j parameters
191
-
192
-
#### Configuration files content description
193
-
194
-
###### config.properties
195
-
- browser.remote =false// flag defines if the remote WebDriver instance will be created. Set "true" to use Selenium Grid. If set to "true", configuration resources from "remote" folder will be used, otherwise resources from "local" folder will be used.
196
-
- element.highlight =true// do highlight elements during actions or not. "Highlight" is made of red border, which is added to each interacted element using specific javascript. Set "false" if you want to switch off this feature.
197
-
198
-
###### timeout.properties
199
-
- timeout.implicit =0// implicit wait timeout. we do not recommend to set non-zero value to it. instead of implicit wait you can take advantage of ConditionalWait:
41
+
6. Call element's methods to perform action with element:
- timeout.condition =30// timeout for waiting actions
206
-
- timeout.script =10// timeout for script execution
207
-
- timeout.pageload =15// page loading timeout
208
-
- timeout.poolinterval =300// retry interval for waiting actions
209
45
210
-
###### browser.properties
211
-
- browser.name=chrome // name of browser to be used. Acceptable names are defined in BrowserName enum. Currently they are: chrome, edge, firefox, iexplorer, safari.
212
-
- browser.opts.file=/src/test/resources/configuration/browser/local/browserOptions.json // path to <a href='#browseroptionsjson'>browserOptions.json</a> file
213
-
- browser.caps.file=/src/test/resources/configuration/browser/local/browserCapabilities.json // path to <a href='#browsercapabilitiesjson'>browserCapabilities.json</a> file
214
-
- browser.args.file=/src/test/resources/configuration/browser/local/browserStartArguments.json // path to <a href='#browserstartargumentsjson'>browserStartArguments.json</a> file
215
-
216
-
###### browser.remote.properties
217
-
- remote.connection.url=http://remotemachine:4444/wd/hub // URL address to remote connection for RemoteWebDriver
218
-
- browser.name=chrome // name of browser to be used. Acceptable names are defined in BrowserName enum. Currently they are: chrome, edge, firefox, iexplorer, safari.
219
-
- browser.opts.file=/src/test/resources/configuration/browser/local/browserOptions.json // path to <a href='#browseroptionsjson'>browserOptions.json</a> file
220
-
- browser.caps.file=/src/test/resources/configuration/browser/local/browserCapabilities.json // path to <a href='#browsercapabilitiesjson'>browserCapabilities.json</a> file
221
-
- browser.args.file=/src/test/resources/configuration/browser/local/browserStartArguments.json // path to <a href='#browserstartargumentsjson'>browserStartArguments.json</a> file
222
-
223
-
Browser configuration consist of three parts: options, capabilities and start arguments. <br>
224
-
Each of this configurations is located in a separate file.<br>
225
-
You can see an example of these configuration files below.<br>
226
-
227
-
###### browserCapabilities.json
228
-
You can read more about desired capabilities at SeleniumHQ wiki: https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities <br>
229
-
Values from this file are set to specific Optionsobject(e.g. ChromeOptions, FirefoxOptionsetc.) with command options.setCapability(key, value);<br>
230
-
AfterwardsthisOptions object is passed as parameter to WebDriver constructor.
231
-
```json
232
-
{
233
-
"chrome": [
234
-
{"enableVNC":true}
235
-
],
236
-
"firefox": [
237
-
{"enableVNC":true}
238
-
],
239
-
"iexplorer": [
240
-
{"ignoreProtectedModeSettings":true}
241
-
]
242
-
}
46
+
7. Quit browser at the end
243
47
```
244
-
245
-
###### browserStartArguments.json
246
-
Values from this file are set to specific Optionsobject(e.g. ChromeOptions, FirefoxOptionsetc.) with command options.addArguments(arg);<br>
247
-
AfterwardsthisOptions object is passed as parameter to WebDriver constructor.
248
-
```json
249
-
{
250
-
"chrome": [
251
-
"--headless",
252
-
"--ignore-certificate-errors"
253
-
],
254
-
"firefox": [
255
-
"-headless"
256
-
]
257
-
}
48
+
browser.quit();
258
49
```
259
-
###### browserOptions.json
260
-
Values from this file are set to specific Optionsobject(e.g. ChromeOptions, FirefoxOptionsetc.) with command options.setExperimentalOption("prefs", chromePrefs); <br>
261
-
Here chromePrefs is a HashMap<String, Object> with key-value pairs from json file. <br>
262
-
-Please note that you can use absolute path as well as relative path for**"download.default_directory"** option. <br>
263
-
To set **relative** path, start it with ".", e.g. **.\\target\\downloads\\**. It will build up as concatenation with prefix gained from **user.dir** system property (ifitisset) or **project.basedir** system property . <br>
264
-
To set **absolute** path you should use full path value, e.g. **C:\\Users\\Public\\Downloads\\** .
265
50
266
-
Afterwards this Options object is passed as parameter to WebDriver constructor.
0 commit comments