Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reference aquality.selenium.core #75

Merged
merged 27 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd1fdf5
rename BrowserManager to AqualityServices,
mialeska Feb 18, 2020
ca5db16
remove some configurations, replaced with core impl
mialeska Feb 18, 2020
7c5960d
get rid of JsonFile, migrate to JsonSettingsFile
mialeska Feb 18, 2020
6b76ca7
refactor element services to use core implementations
mialeska Feb 19, 2020
dbe9c68
restored logging in ElementStateProvider
mialeska Feb 19, 2020
7ea7383
Fixed timeout value
mialeska Feb 19, 2020
fc12bf6
Removed LocalizationManager and ConditionalWait
mialeska Feb 19, 2020
92eb38f
Removed/Replaced ElementActionRetrier
mialeska Feb 19, 2020
1a19561
reworked configuration usage
mialeska Feb 19, 2020
b8225ce
fix sonar issues
mialeska Feb 20, 2020
94fdb5f
replaced container of browser factory with instance field
mialeska Feb 20, 2020
91f7120
corrected action in test
mialeska Feb 20, 2020
50951b6
add element cache configuration into json
mialeska Feb 20, 2020
ad4fade
add missed localization values
mialeska Feb 20, 2020
d88a322
attempt to fix Firefox tests
mialeska Feb 20, 2020
7170161
control localization values, restore some usages
mialeska Feb 20, 2020
e000d17
refactor driver settings
mialeska Feb 20, 2020
6defcb7
Fix sonar issues
mialeska Feb 20, 2020
66ff6ab
Update library self-version in pom file
mialeska Feb 21, 2020
9f8541f
Update library self-version in pom file
mialeska Feb 24, 2020
724dc07
Update README.md
mialeska Feb 24, 2020
569107d
Update README.md
mialeska Feb 24, 2020
81bc4a2
Update Documentation.en.md
mialeska Feb 24, 2020
b5d7f54
Update Documentation.en.md
mialeska Feb 24, 2020
747814e
Update Documentation.en.md
mialeska Feb 24, 2020
62bcc8c
Update Documentation.en.md
mialeska Feb 24, 2020
42a9823
Update Documentation.ru.md
mialeska Feb 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium</artifactId>
<version>1.2.1</version>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>Aquality Selenium</name>
Expand Down Expand Up @@ -67,6 +67,12 @@
</developers>

<dependencies>
<dependency>
mialeska marked this conversation as resolved.
Show resolved Hide resolved
<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>0.0.1</version>
mialeska marked this conversation as resolved.
Show resolved Hide resolved
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
Expand Down
173 changes: 173 additions & 0 deletions src/main/java/aquality/selenium/browser/AqualityServices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package aquality.selenium.browser;

import aquality.selenium.configuration.IBrowserProfile;
import aquality.selenium.configuration.IConfiguration;
import aquality.selenium.core.localization.ILocalizedLogger;
import aquality.selenium.core.logging.Logger;
import aquality.selenium.core.waitings.IConditionalWait;
import aquality.selenium.elements.interfaces.IElementFactory;
import com.google.inject.Injector;

/**
* Controls browser and Aquality services.
*/
public class AqualityServices extends aquality.selenium.core.applications.AqualityServices<Browser> {
private static final ThreadLocal<AqualityServices> INSTANCE_CONTAINER = ThreadLocal.withInitial(AqualityServices::new);
private IBrowserFactory browserFactory;

private AqualityServices() {
super(AqualityServices::getBrowser, () -> new BrowserModule(AqualityServices::getBrowser));
}

private AqualityServices(BrowserModule module) {
super(AqualityServices::getBrowser, () -> module);
}

private static AqualityServices getInstance() {
return INSTANCE_CONTAINER.get();
}

/**
* Gets instance of browser.
*
* @return Instance of desired browser.
*/
public static Browser getBrowser() {
return getInstance().getApp(injector -> AqualityServices.startBrowser());
}

/**
* Check if browser already started or not.
*
* @return true if browser started and false otherwise.
*/
public static boolean isBrowserStarted() {
return getInstance().isAppStarted();
}

/**
* Resolves required service from DI container.
* Note that the service should be binded in {@link BrowserModule}.
*
* @param type class of required service.
* @param <T> type of required service.
* @return required service.
*/
public static <T> T get(Class<T> type) {
return getServiceProvider().getInstance(type);
}

private static Injector getServiceProvider() {
return getInstance().getInjector();
}

/**
* Sets default(local {@link LocalBrowserFactory} or remote {@link RemoteBrowserFactory}) browser factory.
*/
public static void setDefaultBrowserFactory() {
IBrowserFactory browserFactory = getBrowserProfile().isRemote()
? new RemoteBrowserFactory() : new LocalBrowserFactory();
setBrowserFactory(browserFactory);
}

/**
* Gets factory for browser creation.
*
* @return current instance of browser factory.
*/
public static IBrowserFactory getBrowserFactory() {
if (getInstance().browserFactory == null) {
setDefaultBrowserFactory();
}

return getInstance().browserFactory;
}

/**
* Sets custom browser factory.
*
* @param browserFactory Custom implementation of {@link IBrowserFactory}
*/
public static void setBrowserFactory(IBrowserFactory browserFactory) {
getInstance().browserFactory = browserFactory;
}

private static Browser startBrowser() {
return getBrowserFactory().getBrowser();
}

/**
* Sets instance of browser.
*
* @param browser Instance of desired browser.
*/
public static void setBrowser(Browser browser) {
getInstance().setApp(browser);
}

/**
* Reinitializes the dependency injector with custom {@link BrowserModule}.
*
* @param module {@link BrowserModule} object with custom or overriden services.
*/
public static void initInjector(BrowserModule module) {
if (INSTANCE_CONTAINER.get() != null) {
INSTANCE_CONTAINER.remove();
}
INSTANCE_CONTAINER.set(new AqualityServices(module));
}

/**
* Gets logger.
*
* @return instance of logger.
*/
public static Logger getLogger() {
return get(Logger.class);
}

/**
* Gets logger which logs messages in current language.
*
* @return instance of localized logger.
*/
public static ILocalizedLogger getLocalizedLogger() {
return get(ILocalizedLogger.class);
}

/**
* Provides the utility used to wait for some condition.
*
* @return instance of conditional wait.
*/
public static IConditionalWait getConditionalWait() {
return get(IConditionalWait.class);
}

/**
* Gets factory to create elements.
*
* @return Factory of elements.
*/
public static IElementFactory getElementFactory() {
return get(IElementFactory.class);
}

/**
* Gets current profile of browser settings.
*
* @return current browser profile.
*/
public static IBrowserProfile getBrowserProfile() {
return get(IBrowserProfile.class);
}

/**
* Provides interface to access all described configurations.
*
* @return configuration.
*/
public static IConfiguration getConfiguration() {
return get(IConfiguration.class);
}
}
Loading