Skip to content

Commit

Permalink
Merge pull request #41 from TikhomirovSergey/master
Browse files Browse the repository at this point in the history
Redesigned sub-classes of DurationSupplier
  • Loading branch information
TikhomirovSergey authored Oct 29, 2018
2 parents 07d471e + 557d71c commit b0e30e2
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 162 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
globalVersion = '0.5.0-ALPHA'
globalVersion = '0.5.1-ALPHA'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ public abstract class DurationSupplier implements Supplier<Duration> {

private final DurationUnitPropertySupplier durationUnitPropertySupplier;
private final DurationValuePropertySupplier durationValuePropertySupplier;
private final Duration returnWhenNotDefined;

protected DurationSupplier(DurationUnitPropertySupplier durationUnitPropertySupplier,
DurationValuePropertySupplier durationValuePropertySupplier) {
DurationValuePropertySupplier durationValuePropertySupplier, Duration returnWhenNotDefined) {
checkArgument(returnWhenNotDefined != null, "Default duration value should be defined");
checkArgument(durationUnitPropertySupplier != null, "A supplier of time unit should be defined");
checkArgument(durationValuePropertySupplier != null, "A supplier of time value should be defined");
this.returnWhenNotDefined = returnWhenNotDefined;
this.durationUnitPropertySupplier = durationUnitPropertySupplier;
this.durationValuePropertySupplier = durationValuePropertySupplier;
}

/**
* This method creates supplied time unit value or returns given value when {@link DurationUnitPropertySupplier#get()}
* This method creates supplied time unit value or returns default value when {@link DurationUnitPropertySupplier#get()}
* or {@link DurationValuePropertySupplier#get()} return {@code null}
*
* @param returnWhenNotDefined a duration value that should be returned when {@link DurationUnitPropertySupplier#get()}
* or {@link DurationValuePropertySupplier#get()} return {@code null}
* @return built duration value.
*/
protected Duration getDuration(Duration returnWhenNotDefined) {
public Duration get() {
if (durationUnitPropertySupplier.get() == null || durationValuePropertySupplier.get() == null) {
return returnWhenNotDefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ static class CleanStringAction extends SequentialActionSupplier<Object, String,
//this method was added for the unit testing
CleanStringAction andThen(Function<Object, String> function, String...strings) {
return super.andThen("Clean string value of the object of given strings",
function, strings);
function, (Object[]) strings);
}

//this method was added for the unit testing
CleanStringAction andThen(String string, String...strings) {
return super.andThen("Clean string value " + string + " of given strings",
string, strings);
string, (Object[]) strings);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion data.base.api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tasks.withType(JavaCompile) {
}

compileJava.doLast {
enhanceJdoEntities.execute()
enhanceJdoEntities.exec()
}

task generateStaticMetamodel(type: JavaCompile, group: 'build', description: 'Generates JDO static metamodel') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public final class DefaultWaitingForSelectionResultProperty extends DurationSupp

private DefaultWaitingForSelectionResultProperty(DurationUnitPropertySupplier durationUnitPropertySupplier,
DurationValuePropertySupplier durationValuePropertySupplier) {
super(durationUnitPropertySupplier, durationValuePropertySupplier);
}

@Override
public Duration get() {
return getDuration(ofSeconds(5));
super(durationUnitPropertySupplier, durationValuePropertySupplier, ofSeconds(5));
}
}
3 changes: 0 additions & 3 deletions selenium/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ dependencies {
compile project(':core.api')
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: seleniumVersion
compile group: 'org.hamcrest', name: 'java-hamcrest', version: hamcrestVersion
compile (group: 'com.codeborne', name: 'phantomjsdriver', version: '1.4.4') {
exclude group: 'org.seleniumhq.selenium'
}
compile (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.0.0') {
exclude group: 'org.seleniumhq.selenium'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.tinkoff.qa.neptune.selenium.properties;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;

import java.util.function.Supplier;

public interface CapabilitySupplier extends Supplier<Capabilities> {
public interface CapabilitySupplier extends Supplier<MutableCapabilities> {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.tinkoff.qa.neptune.selenium.properties;

import org.openqa.selenium.MutableCapabilities;
import ru.tinkoff.qa.neptune.core.api.properties.PropertySupplier;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.chrome.ChromeOptions;
Expand All @@ -9,7 +10,6 @@
import org.openqa.selenium.opera.OperaOptions;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.safari.SafariOptions;

import java.util.List;
Expand All @@ -19,9 +19,8 @@
import static java.util.stream.Collectors.toList;
import static org.apache.commons.lang3.ArrayUtils.contains;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

public enum CapabilityTypes implements PropertySupplier<Capabilities> {
public enum CapabilityTypes implements PropertySupplier<MutableCapabilities> {
/**
* Capabilities for the starting of {@link org.openqa.selenium.remote.RemoteWebDriver}
*/
Expand All @@ -43,13 +42,16 @@ public enum CapabilityTypes implements PropertySupplier<Capabilities> {
* @return built {@link Capabilities}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
var browser = CommonCapabilityProperties.BROWSER_NAME.get();
if (CommonCapabilityProperties.BROWSER_NAME.get() == null ||
isBlank(String.valueOf(CommonCapabilityProperties.BROWSER_NAME.get()))) {
throw new IllegalArgumentException(format("The property %s should be defined",
CommonCapabilityProperties.BROWSER_NAME.getPropertyName()));
}
return super.get();
var result = super.get();
result.setCapability(CapabilityType.BROWSER_NAME, browser);
return result;
}
},

Expand All @@ -73,7 +75,7 @@ public Capabilities get() {
* @return built {@link ChromeOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new ChromeOptions().merge(super.get());
}
},
Expand All @@ -98,7 +100,7 @@ public Capabilities get() {
* @return built {@link EdgeOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new EdgeOptions().merge(super.get());
}
},
Expand All @@ -123,7 +125,7 @@ public Capabilities get() {
* @return built {@link FirefoxOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new FirefoxOptions().merge(super.get());
}
},
Expand All @@ -148,7 +150,7 @@ public Capabilities get() {
* @return built {@link InternetExplorerOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new InternetExplorerOptions().merge(super.get());
}
},
Expand All @@ -173,7 +175,7 @@ public Capabilities get() {
* @return built {@link OperaOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new OperaOptions().merge(super.get());
}
},
Expand All @@ -198,38 +200,9 @@ public Capabilities get() {
* @return built {@link SafariOptions}
*/
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new SafariOptions().merge(super.get());
}
},

/**
* Capabilities for the starting of {@link org.openqa.selenium.phantomjs.PhantomJSDriver}
*/
PHANTOM_JS("phantomJs") {

/**
* Creates {@link Capabilities} with following properties:
* <p>
* <p>{@code web.driver.capability.platformName} to define name of a supported platform.
* Windows, Linux etc. This is not the necessary property. @see org.openqa.selenium.Platform
* <p>{@code web.driver.capability.javascriptEnabled} to enable or to disable js. Possible values are
* {@code true} or {@code false}. By default js is enabled. This is not the necessary property.
* <p>{@code web.driver.capability.browserVersion} to define a version of browser. This is not the necessary
* property.
* <p>{@code remote.capability.suppliers} to define additional capabilities. It is a string with name of a
* supplier.
* @see CapabilitySupplier
* @see AdditionalCapabilitiesFor
*
* @return built {@link Capabilities} for {@link org.openqa.selenium.phantomjs.PhantomJSDriver}
*/
@Override
public Capabilities get() {
var capabilities = new DesiredCapabilities().merge(super.get());
capabilities.setCapability(BROWSER_NAME, BrowserType.PHANTOMJS);
return capabilities;
}
};

private static final String CAPABILITY_SUPPLIERS = "capability.suppliers";
Expand All @@ -240,11 +213,8 @@ public Capabilities get() {
}

@Override
public Capabilities get() {
var desiredCapabilities = new DesiredCapabilities();
ofNullable(CommonCapabilityProperties.BROWSER_NAME.get()).ifPresent(o ->
desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, o));

public MutableCapabilities get() {
var desiredCapabilities = new MutableCapabilities();
ofNullable(CommonCapabilityProperties.PLATFORM_NAME.get()).ifPresent(o ->
desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, o));

Expand Down Expand Up @@ -283,8 +253,9 @@ public enum CommonCapabilityProperties implements PropertySupplier<Object> {
* <p>{@link BrowserType#IEXPLORE}
* <p>{@link BrowserType#OPERA_BLINK}
* <p>{@link BrowserType#SAFARI}
* <p>{@link BrowserType#PHANTOMJS}
*
*
* It has sense to define value of the property when value of the property {@link SupportedWebDriverProperty#SUPPORTED_WEB_DRIVER_PROPERTY_PROPERTY}
* is {@link SupportedWebDrivers#REMOTE_DRIVER}
*/
BROWSER_NAME(format("web.driver.capability.%s", CapabilityType.BROWSER_NAME)),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
Expand Down Expand Up @@ -65,10 +64,6 @@ public WebDriverManager getWebDriverManager() {
return operadriver();
}

if (BrowserType.PHANTOMJS.equalsIgnoreCase(browserName)) {
return phantomjs();
}

return null;
}

Expand Down Expand Up @@ -138,16 +133,6 @@ public WebDriverManager getWebDriverManager() {
public WebDriverManager getWebDriverManager() {
return null;
}
},

/**
* This item describes instantiation of {@link PhantomJSDriver}
*/
PHANTOM_JS_DRIVER(PhantomJSDriver.class, CapabilityTypes.PHANTOM_JS, false) {
@Override
public WebDriverManager getWebDriverManager() {
return phantomjs();
}
};

private final Class<? extends WebDriver> webDriverClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,60 @@

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.function.Supplier;

import static ru.tinkoff.qa.neptune.selenium.properties.WaitingProperties.TimeUnitProperties.*;
import static ru.tinkoff.qa.neptune.selenium.properties.WaitingProperties.TimeValueProperties.*;
import static java.time.Duration.of;
import static java.time.temporal.ChronoUnit.MINUTES;

public enum WaitingProperties implements Supplier<Duration> {
public final class WaitingProperties extends DurationSupplier {
/**
* Returns duration of the waiting for some web elements
* are present and suit some criteria. When {@code "waiting.for.elements.time.unit"} or
* {@code "waiting.for.elements.time"} are not defined then it returns 1 minute.
* Otherwise it returns defined duration value.
*/
ELEMENT_WAITING_DURATION(ELEMENT_WAITING_TIME_UNIT, ELEMENT_WAITING_TIME_VALUE),
public static final WaitingProperties ELEMENT_WAITING_DURATION = new WaitingProperties(ELEMENT_WAITING_TIME_UNIT,
ELEMENT_WAITING_TIME_VALUE, of(1, MINUTES));

/**
* Returns duration of the waiting for appearance of an alert.
* When {@code "waiting.alert.time.unit"} or {@code "waiting.alert.time"}
* are not defined then it returns 1 minute. Otherwise it returns defined duration value.
*/
WAITING_ALERT_TIME_DURATION(WAITING_ALERT_TIME_UNIT, WAITING_ALERT_TIME_VALUE),
public static final WaitingProperties WAITING_ALERT_TIME_DURATION = new WaitingProperties(WAITING_ALERT_TIME_UNIT,
WAITING_ALERT_TIME_VALUE, of(1, MINUTES));

/**
* Returns duration of the waiting for some window.
* When {@code "waiting.window.time.unit"} or {@code "waiting.window..time"}
* are not defined then it returns 1 minute. Otherwise it returns defined duration value.
*/
WAITING_WINDOW_TIME_DURATION(WAITING_WINDOW_TIME_UNIT, WAITING_WINDOW_TIME_VALUE),
public static final WaitingProperties WAITING_WINDOW_TIME_DURATION = new WaitingProperties(WAITING_WINDOW_TIME_UNIT,
WAITING_WINDOW_TIME_VALUE, of(1, MINUTES));

/**
* Returns duration of the waiting for the switching to some frame succeeded.
* When {@code "waiting.frame.switching.time.unit"} or {@code "waiting.frame.switching.time"}
* are not defined then it returns 1 minute. Otherwise it returns defined duration value.
*/
WAITING_FRAME_SWITCHING_DURATION(WAITING_FRAME_SWITCHING_TIME_UNIT, WAITING_FRAME_SWITCHING_TIME_VALUE),
public static final WaitingProperties WAITING_FRAME_SWITCHING_DURATION = new WaitingProperties(WAITING_FRAME_SWITCHING_TIME_UNIT,
WAITING_FRAME_SWITCHING_TIME_VALUE, of(1, MINUTES));

/**
* Returns duration of the waiting for waiting for a page is loaded.
* When {@code "waiting.for.page.loaded.time.unit"} or {@code "waiting.for.page.loaded.time"}
* are not defined then it returns 1 minute. Otherwise it returns defined duration value.
*/
WAITING_FOR_PAGE_LOADED_DURATION(WAITING_FOR_PAGE_LOADED_TIME_UNIT, WAITING_FOR_PAGE_LOADED_TIME_VALUE);
public static final WaitingProperties WAITING_FOR_PAGE_LOADED_DURATION = new WaitingProperties(WAITING_FOR_PAGE_LOADED_TIME_UNIT,
WAITING_FOR_PAGE_LOADED_TIME_VALUE, of(1, MINUTES));

private final DurationSupplier durationSupplier;

WaitingProperties(TimeUnitProperties timeUnit, TimeValueProperties timeValue) {
durationSupplier = new DurationSupplier(timeUnit, timeValue) {
@Override
public Duration get() {
return getDuration(of(1, MINUTES));
}
};
private WaitingProperties(TimeUnitProperties durationUnitPropertySupplier,
TimeValueProperties durationValuePropertySupplier,
Duration returnWhenNotDefined) {
super(durationUnitPropertySupplier, durationValuePropertySupplier, returnWhenNotDefined);
}

@Override
public Duration get() {
return durationSupplier.get();
}

public enum TimeUnitProperties implements DurationUnitPropertySupplier {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.tinkoff.qa.neptune.selenium.test.capability.suppliers;

import org.openqa.selenium.MutableCapabilities;
import ru.tinkoff.qa.neptune.selenium.properties.AdditionalCapabilitiesFor;
import ru.tinkoff.qa.neptune.selenium.properties.CapabilitySupplier;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.HashMap;
Expand All @@ -12,7 +12,7 @@
@AdditionalCapabilitiesFor(type = CHROME, supplierName = "withExperimental")
public class ChromeTestSupplierWithExperimentalOption implements CapabilitySupplier {
@Override
public Capabilities get() {
public MutableCapabilities get() {
return new ChromeOptions().setExperimentalOption("experimentalOption", new HashMap<>())
.addArguments("--use-fake-device-for-media-stream",
"--start-maximized", "--enable-automation",
Expand Down
Loading

0 comments on commit b0e30e2

Please sign in to comment.