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

video-recorder #8

Merged
merged 6 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>qa-utils</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<type>jar</type>
</dependency>
<dependency>
Expand All @@ -70,13 +70,13 @@
<dependency>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>allure-helper</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>video-recorder</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public static String highlightElementOn(WebElement webElement) {
js.executeScript("arguments[0].style.border='3px solid red'", webElement);
return style;
} catch (Exception e) {
log.debug("Something went wrong with element highlight", e);
log.warn("Something went wrong with element highlight", e);
return null;
}
}
Expand Down
50 changes: 19 additions & 31 deletions src/main/java/ru/sbtqa/tag/pagefactory/Page.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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 Expand Up @@ -38,7 +39,6 @@
import ru.yandex.qatools.htmlelements.element.CheckBox;
import ru.yandex.qatools.htmlelements.element.HtmlElement;
import ru.yandex.qatools.htmlelements.element.TypifiedElement;
import static java.lang.String.format;

/**
* Base page object class. Contains basic actions with elements, search methods
Expand Down Expand Up @@ -571,6 +571,7 @@ public List<WebElement> findListOfElements(String listTitle) throws PageExceptio
* ${@link Core#findListOfElements(String, Class, Object)} for detailed
* description
*
* @param blockPath full path or just a name of the block to search
* @param listTitle value of ElementTitle annotation of required element
* @param type type of elements in list that is being searched for
* @param <T> type of elements in returned list
Expand All @@ -588,6 +589,7 @@ public <T extends WebElement> List<T> findListOfElementsInBlock(String blockPath
* ${@link Core#findListOfElements(String, Class, Object)} for detailed
* description
*
* @param blockPath full path or just a name of the block to search
* @param listTitle value of ElementTitle annotation of required element
* @return list of WebElement's
* @throws PageException if nothing found or current page is not initialized
Expand Down Expand Up @@ -638,8 +640,9 @@ public List<HtmlElement> findBlocks(String blockPath) throws NoSuchElementExcept
* @param block block title, or a block chain string separated with '-&gt;'
* symbols
* @param actionTitle title of the action to execute
* @throws java.lang.NoSuchMethodException if required method couldn't be found
*/
public void executeMethodByTitleInBlock(String block, String actionTitle) {
public void executeMethodByTitleInBlock(String block, String actionTitle) throws NoSuchMethodException {
executeMethodByTitleInBlock(block, actionTitle, new Object[0]);
}

Expand All @@ -650,8 +653,9 @@ public void executeMethodByTitleInBlock(String block, String actionTitle) {
* @param blockPath block title, or a block chain string separated with '-&gt;' symbols
* @param actionTitle title of the action to execute
* @param parameters parameters that will be passed to method
* @throws java.lang.NoSuchMethodException if required method couldn't be found
*/
public void executeMethodByTitleInBlock(String blockPath, String actionTitle, Object... parameters) {
public void executeMethodByTitleInBlock(String blockPath, String actionTitle, Object... parameters) throws NoSuchMethodException {
HtmlElement block = findBlock(blockPath);
Method[] methods = block.getClass().getMethods();
for (Method method : methods) {
Expand All @@ -665,11 +669,13 @@ public void executeMethodByTitleInBlock(String blockPath, String actionTitle, Ob
}
break;
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new AutotestError(format("Could not find action '%s' in block the following block: '%s'",
actionTitle, blockPath));
throw new FactoryRuntimeException(format("Failed to execute method '%s' in the following block: '%s'",
actionTitle, blockPath), e);
}
}
}

throw new NoSuchMethodException(format("There is no '%s' method in block '%s'", actionTitle, blockPath));
}

/**
Expand Down Expand Up @@ -1050,6 +1056,7 @@ public WebElement getElementByTitle(String title) throws PageException {
return Core.getElementByField(this, field);
}
}

throw new ElementNotFoundException(format("Element '%s' is not present on current page '%s''", title, this.getTitle()));
}

Expand All @@ -1074,43 +1081,25 @@ public <T extends TypifiedElement> T getTypifiedElementByTitle(String title) thr
/**
* Find method with corresponding title on current page, and execute it
*
* @param <T> type parameter of the returned object
* @param title title of the method to call
* @param type method return type
* @param param parameters that will be passed to method
* @return method execution result, depends on the method return type
* @throws java.lang.NoSuchMethodException if required method couldn't be found
*/
public <T extends Object> T executeMethodByTitle(String title, Class<T> type, Object... param) throws NoSuchMethodException {
public void executeMethodByTitle(String title, Object... param) throws NoSuchMethodException {
List<Method> methods = Core.getDeclaredMethods(this.getClass());
for (Method method : methods) {
if (Core.isRequiredAction(method, title)) {
try {
method.setAccessible(true);
return type.cast(MethodUtils.invokeMethod(this, method.getName(), param));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
log.error("Failed to invoke method '" + title + "'", ex);
MethodUtils.invokeMethod(this, method.getName(), param);
return;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new FactoryRuntimeException("Failed to invoke method", e);
}
}
}

throw new NoSuchMethodException(
"There is no " + title + " method on " + this.getTitle() + " page object.");
}

/**
* Execute method by MethodTitle
* //TODO: looks like this one makes no sense. We suppose that called method will return current page instance, why
* would it?
*
* @param <T> type parameter of the returned object
* @param title title of the method to call
* @param param parameters that will be passed to method
* @return method execution result, depends on the method return type
* @throws java.lang.NoSuchMethodException if required method couldn't be found
*/
public <T extends Object> T executeMethodByTitle(String title, Object... param) throws NoSuchMethodException {
return executeMethodByTitle(title, (Class<T>) this.getClass(), param);
throw new NoSuchMethodException("There is no '" + title + "' method on '" + this.getTitle() + "' page object");
}

/**
Expand All @@ -1119,9 +1108,8 @@ public <T extends Object> T executeMethodByTitle(String title, Object... param)
* @param title title of the validation rule
* @param params parameters passed to called method
* @throws ru.sbtqa.tag.pagefactory.exceptions.PageException if couldn't find corresponding validation rule
* @throws ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException if failed tyo invoke method
*/
public void fireValidationRule(String title, Object... params) throws PageException, FactoryRuntimeException {
public void fireValidationRule(String title, Object... params) throws PageException {
Method[] methods = this.getClass().getMethods();
for (Method method : methods) {
if (null != method.getAnnotation(ValidationRule.class)
Expand Down
47 changes: 20 additions & 27 deletions src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import org.apache.commons.lang3.SystemUtils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Proxy;
Expand All @@ -34,7 +35,7 @@
import ru.sbtqa.tag.pagefactory.exceptions.UnsupportedBrowserException;
import ru.sbtqa.tag.pagefactory.support.DesiredCapabilitiesParser;
import ru.sbtqa.tag.qautils.properties.Props;
import ru.sbtqa.tag.videorecorder.VideoRecorderImpl;
import ru.sbtqa.tag.videorecorder.VideoRecorder;

public class PageFactory {

Expand All @@ -43,7 +44,7 @@ public class PageFactory {
private static WebDriver webDriver;
private static Actions actions;
private static PageShell PageFactoryCore;
private static VideoRecorderImpl videoRecorder;
private static VideoRecorder videoRecorder;
private static BrowserMobProxy proxy; // for use proxy, use Props proxy.enable = true
private static final Map<Class<? extends Page>, Map<Field, String>> PAGES_REPOSITORY = new HashMap<>();

Expand All @@ -66,18 +67,12 @@ public class PageFactory {
*/
public static WebDriver getWebDriver() {
if (null == webDriver) {
// TODO revert video record
// if (getVideoRecorder() == null && Boolean.valueOf(Props.get("videoRecordingEnabled"))) {
// try {
// videoRecorder = new VideoRecorder();
// videoRecorder.startRecording();
// } catch (IOException e) {
// log.warn("Video recording can not be started", e);
// }
// }
if (Boolean.valueOf(Props.get("video.enable"))) {
VideoRecorder.getInstance().startRecording();
}

for (int i = 1; i <= ATTEMPTS_TO_START_WEBDRIVER; i++) {
log.warn("Attempt #" + i + " to start web driver");
log.info("Attempt #" + i + " to start web driver");
try {
createWebDriver();
break;
Expand Down Expand Up @@ -214,17 +209,20 @@ public static void dispose() {
log.warn("Failed to quit web driver", e);
} finally {
try {
//TODO take out into a separate method
// Wait for processes disappear, this might take a few seconds
String brwsrNm = BROWSER_NAME.toLowerCase().trim();
if ("ie".equals(brwsrNm)) {
brwsrNm = "iexplore";
}
int i = 0;
while (i <= 10) {
if (Runtime.getRuntime().exec("tasklist | findstr " + brwsrNm).waitFor() == 0) {
Thread.sleep(1000);
} else {
i = 10;
if (SystemUtils.IS_OS_WINDOWS) {
String brwsrNm = BROWSER_NAME.toLowerCase().trim();
if ("ie".equals(brwsrNm)) {
brwsrNm = "iexplore";
}
int i = 0;
while (i <= 10) {
if (Runtime.getRuntime().exec("tasklist | findstr " + brwsrNm).waitFor() == 0) {
Thread.sleep(1000);
} else {
i = 10;
}
}
}
} catch (IOException | InterruptedException e) {
Expand All @@ -234,11 +232,6 @@ public static void dispose() {

setWebDriver(null);
PageFactoryCore = null;

// //Закрытие коннектов к базе
// if (null != dbConnectionFactory) {
// dbConnectionFactory.closeConnections();
// }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ru/sbtqa/tag/pagefactory/PageShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Page getPage(String packageName, String title) throws PageInitializationE
*/
public Page getCurrentPage() throws PageInitializationException {
if (null == currentPage) {
throw new PageInitializationException(new Exception("Current page not initialized!"));
throw new PageInitializationException("Current page not initialized!");
} else {
return currentPage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
return;
}

if (Boolean.valueOf(Props.get("highlightActiveElements"))) {
if (Boolean.valueOf(Props.get("video.highlight.enable"))) {
elementHighlightStyle = DriverExtensions.highlightElementOn(targetWebElement);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
// ExperianModel.initElements(PageFactory.getWebDriver(), PageFactory.getInstance().currentPage);
// }

if (Boolean.valueOf(Props.get("highlightActiveElements"))) {
if (Boolean.valueOf(Props.get("video.highlight.enable"))) {
DriverExtensions.highlightElementOff(targetWebElement, elementHighlightStyle);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void setUp() {
}

try {
//TODO fix if task.to.kill does not exist in application.properties
String[] tasks = Props.get("tasks.to.kill").split(",");
if (tasks.length > 0) {
for (String task : tasks) {
Expand Down Expand Up @@ -96,17 +97,5 @@ public void setUp() {
@After
public void tearDown() {
PageFactory.dispose();

//TODO зкоментить
// if (PageFactory.getVideoRecorder() != null && PageFactory.getVideoRecorder().isVideoStarted()) {
// log.info("Video is saving...");
// Thread.sleep(5000);
// String videoPath = PageFactory.getVideoRecorder().stopRecording();
// if (videoPath != null) {
// //TODO положить в аллюр. Разобраться как сделать
// //addVideoParameter();
// PageFactory.setVideoRecorderToNull();
// }
// }
}
}
Loading