Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from sbtqa/properties-sample
Browse files Browse the repository at this point in the history
Properties sample
  • Loading branch information
clicman authored Feb 15, 2017
2 parents 6bf2060 + 453913f commit 7c458af
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 99 deletions.
1 change: 0 additions & 1 deletion src/main/java/ru/sbtqa/tag/pagefactory/Page.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.sbtqa.tag.pagefactory;

import static java.lang.String.format;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ public class PageFactory {
private static boolean aspectsDisabled = false;

private static final String ENVIRONMENT = Props.get("driver.environment");
private static final String INITIAL_URL = Props.get("driver.url");
private static final String PAGES_PACKAGE = Props.get("page.package");
private static final String TIMEOUT = Props.get("page.load.timeout");
private static final String BROWSER_NAME = Props.get("browser.name");

private static final String ENVIRONMENT_WEB = "web";
private static final String ENVIRONMENT_MOBILE = "mobile";
Expand Down Expand Up @@ -100,13 +98,6 @@ public static Actions getActions() {
return actions;
}

/**
* @return the browserName
*/
public static String getBrowserName() {
return BROWSER_NAME;
}

/**
* @return the pagesPackage
*/
Expand Down Expand Up @@ -167,11 +158,4 @@ public static Environment getEnvironment() {
throw new FactoryRuntimeException("Environment '" + ENVIRONMENT + "' is not supported");
}
}

/**
* @return the INITIAL_URL
*/
public static String getInitialUrl() {
return INITIAL_URL;
}
}
18 changes: 2 additions & 16 deletions src/main/java/ru/sbtqa/tag/pagefactory/PageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import ru.sbtqa.tag.pagefactory.annotations.PageEntry;
import ru.sbtqa.tag.pagefactory.exceptions.PageInitializationException;
import ru.sbtqa.tag.qautils.errors.AutotestError;
import ru.sbtqa.tag.qautils.properties.Props;

public class PageWrapper {

Expand Down Expand Up @@ -142,7 +141,8 @@ public Page changeUrlByTitle(String packageName, String title) throws PageInitia
} else {
try {
URL currentUrl = new URL(PageFactory.getWebDriver().getCurrentUrl());
String finalUrl = currentUrl.getProtocol() + "://" + currentUrl.getAuthority() + getUrlPrefix() + ((PageEntry) annotation).url();
String finalUrl = new URL(currentUrl.getProtocol(), currentUrl.getHost(), currentUrl.getPort(),
((PageEntry) annotation).url()).toString();
PageFactory.getWebDriver().navigate().to(finalUrl);
} catch (MalformedURLException ex) {
LOG.error("Failed to get current url", ex);
Expand All @@ -155,20 +155,6 @@ public Page changeUrlByTitle(String packageName, String title) throws PageInitia
throw new AutotestError("Page " + title + " doesn't have fast URL in PageEntry");
}

/**
*
* @return
*/
private String getUrlPrefix() {
String prefix = Props.get("webdriver.url.prefix");
if (!"".equals(prefix)) {
return ((prefix.startsWith("/")) ? "" : "/")
+ prefix
+ ((prefix.endsWith("/")) ? "" : "/");
}
return "/";
}

/**
*
* @param packageName TODO
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/ru/sbtqa/tag/pagefactory/aspects/ClickAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ru.sbtqa.tag.datajack.Stash;
import ru.sbtqa.tag.pagefactory.Page;
import ru.sbtqa.tag.pagefactory.PageFactory;
import ru.sbtqa.tag.pagefactory.drivers.TagWebDriver;
import ru.sbtqa.tag.pagefactory.extensions.WebExtension;
import ru.sbtqa.tag.pagefactory.support.Environment;
import ru.sbtqa.tag.qautils.properties.Props;
Expand Down Expand Up @@ -41,8 +42,8 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
}

String elementHighlightStyle = null;
boolean isVideoHighlightEnable = Boolean.valueOf(Props.get("video.highlight.enable"));
if (isVideoHighlightEnable) {
boolean isVideoHighlightEnabled = Boolean.valueOf(Props.get("video.highlight.enabled"));
if (isVideoHighlightEnabled) {
elementHighlightStyle = WebExtension.highlightElementOn(targetWebElement);
}

Expand All @@ -52,7 +53,7 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {

if (!PageFactory.isAspectsDisabled()) {
Actions actions = new Actions(PageFactory.getWebDriver());
if ("IE".equals(PageFactory.getBrowserName())) {
if ("IE".equals(TagWebDriver.getBrowserName())) {
Dimension size = PageFactory.getWebDriver().manage().window().getSize();
Point elementLocation = (targetWebElement).getLocation();
Dimension elementSize = (targetWebElement).getSize();
Expand All @@ -64,7 +65,7 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
}
}

switch (PageFactory.getBrowserName()) {
switch (TagWebDriver.getBrowserName()) {
case "Chrome":
case "IE":
actions.moveToElement(targetWebElement);
Expand All @@ -82,7 +83,7 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
PageFactory.getInstance().getPage(elementRedirect);
}

if (isVideoHighlightEnable) {
if (isVideoHighlightEnabled) {
WebExtension.highlightElementOff(targetWebElement, elementHighlightStyle);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
Expand All @@ -21,14 +20,20 @@ public class TagMobileDriver {
private static final Logger LOG = LoggerFactory.getLogger(TagMobileDriver.class);

private static AppiumDriver<AndroidElement> mobileDriver;

private static final String APPIUM_URL = Props.get("appium.url");
private static final String APPIUM_DEVICE_NAME = Props.get("appium.device.name");
private static final String APPIUM_DEVICE_PLATFORM = Props.get("appium.device.platform");
private static final String APPIUM_APP_PACKAGE = Props.get("appium.app.package");
private static final String APPIUM_APP_ACTIVITY = Props.get("appium.app.activity");
private static final String VIDEO_ENABLED = Props.get("video.enabled", "false");

public static AppiumDriver<AndroidElement> getDriver() {
if (Environment.MOBILE != PageFactory.getEnvironment()) {
throw new FactoryRuntimeException("Failed to get mobile driver while environment is not mobile");
}

if (null == mobileDriver) {
if (Boolean.valueOf(Props.get("video.enable"))) {
if (Boolean.valueOf(VIDEO_ENABLED)) {
VideoRecorder.getInstance().startRecording();
}

Expand All @@ -39,20 +44,20 @@ public static AppiumDriver<AndroidElement> getDriver() {

private static void createDriver() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", Props.get("appium.device.name"));
capabilities.setCapability("platformVersion", Props.get("appium.device.platform"));
capabilities.setCapability("appPackage", Props.get("appium.app.package"));
capabilities.setCapability("appActivity", Props.get("appium.app.activity"));
capabilities.setCapability("deviceName", APPIUM_DEVICE_NAME);
capabilities.setCapability("platformVersion", APPIUM_DEVICE_PLATFORM);
capabilities.setCapability("appPackage", APPIUM_APP_PACKAGE);
capabilities.setCapability("appActivity", APPIUM_APP_ACTIVITY);
capabilities.setCapability("autoGrantPermissions", "true");
capabilities.setCapability("unicodeKeyboard", "true");
capabilities.setCapability("resetKeyboard", "true");
LOG.info("Capabilities are {}", capabilities);

URL url;
try {
url = new URL(PageFactory.getInitialUrl());
url = new URL(APPIUM_URL);
} catch (MalformedURLException e) {
throw new FactoryRuntimeException("Failed to connect to appium on url " + PageFactory.getInitialUrl(), e);
throw new FactoryRuntimeException("Could not parse appium url. Check 'appium.url' property", e);
}

setAspectsDisabled(true);
Expand Down
Loading

0 comments on commit 7c458af

Please sign in to comment.