diff --git a/pom.xml b/pom.xml
index a3ec19f..41bde5b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,7 @@
ru.sbtqa.tag
qa-utils
- 1.0.2
+ 1.0.3
jar
@@ -70,13 +70,13 @@
ru.sbtqa.tag
allure-helper
- 1.0.2
+ 1.0.3
jar
ru.sbtqa.tag
video-recorder
- 1.0.3
+ 1.0.4
jar
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/DriverExtensions.java b/src/main/java/ru/sbtqa/tag/pagefactory/DriverExtensions.java
index d7f5a09..c9ad5b4 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/DriverExtensions.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/DriverExtensions.java
@@ -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;
}
}
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/Page.java b/src/main/java/ru/sbtqa/tag/pagefactory/Page.java
index 0ceb9d9..27a79a8 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/Page.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/Page.java
@@ -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;
@@ -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
@@ -571,6 +571,7 @@ public List 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 type of elements in returned list
@@ -588,6 +589,7 @@ public List 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
@@ -638,8 +640,9 @@ public List findBlocks(String blockPath) throws NoSuchElementExcept
* @param block block title, or a block chain string separated with '->'
* 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]);
}
@@ -650,8 +653,9 @@ public void executeMethodByTitleInBlock(String block, String actionTitle) {
* @param blockPath block title, or a block chain string separated with '->' 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) {
@@ -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));
}
/**
@@ -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()));
}
@@ -1074,43 +1081,25 @@ public T getTypifiedElementByTitle(String title) thr
/**
* Find method with corresponding title on current page, and execute it
*
- * @param 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 executeMethodByTitle(String title, Class type, Object... param) throws NoSuchMethodException {
+ public void executeMethodByTitle(String title, Object... param) throws NoSuchMethodException {
List 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 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 executeMethodByTitle(String title, Object... param) throws NoSuchMethodException {
- return executeMethodByTitle(title, (Class) this.getClass(), param);
+ throw new NoSuchMethodException("There is no '" + title + "' method on '" + this.getTitle() + "' page object");
}
/**
@@ -1119,9 +1108,8 @@ public 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)
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java b/src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java
index f1a08dd..2567c7f 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/PageFactory.java
@@ -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;
@@ -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 {
@@ -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, Map> PAGES_REPOSITORY = new HashMap<>();
@@ -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;
@@ -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) {
@@ -234,11 +232,6 @@ public static void dispose() {
setWebDriver(null);
PageFactoryCore = null;
-
-// //Закрытие коннектов к базе
-// if (null != dbConnectionFactory) {
-// dbConnectionFactory.closeConnections();
-// }
}
/**
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/PageShell.java b/src/main/java/ru/sbtqa/tag/pagefactory/PageShell.java
index e5c0597..1c73605 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/PageShell.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/PageShell.java
@@ -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;
}
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/aspects/ClickAspect.java b/src/main/java/ru/sbtqa/tag/pagefactory/aspects/ClickAspect.java
index dbf0872..3cc62e6 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/aspects/ClickAspect.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/aspects/ClickAspect.java
@@ -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);
}
@@ -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);
}
}
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/stepdefs/SetupDefsBase.java b/src/main/java/ru/sbtqa/tag/pagefactory/stepdefs/SetupDefsBase.java
index 7e39d20..a196ac9 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/stepdefs/SetupDefsBase.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/stepdefs/SetupDefsBase.java
@@ -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) {
@@ -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();
-// }
-// }
}
}
diff --git a/src/main/java/ru/sbtqa/tag/pagefactory/support/AllureRunListener.java b/src/main/java/ru/sbtqa/tag/pagefactory/support/AllureRunListener.java
index 0c74cfd..3d1675b 100644
--- a/src/main/java/ru/sbtqa/tag/pagefactory/support/AllureRunListener.java
+++ b/src/main/java/ru/sbtqa/tag/pagefactory/support/AllureRunListener.java
@@ -6,6 +6,7 @@
import org.slf4j.LoggerFactory;
import ru.sbtqa.tag.allurehelper.AllureNonCriticalFailure;
import ru.sbtqa.tag.qautils.properties.Props;
+import ru.sbtqa.tag.videorecorder.VideoRecorder;
public class AllureRunListener extends ru.sbtqa.tag.allurehelper.TagAllureRunListener {
@@ -17,37 +18,36 @@ public class AllureRunListener extends ru.sbtqa.tag.allurehelper.TagAllureRunLis
*/
@Override
public void testFailure(Failure failure) {
-
-// if (PageFactory.getVideoRecorder() != null && PageFactory.getVideoRecorder().isVideoStarted()) {
-// String videoPath = PageFactory.getVideoRecorder().stopRecording();
-// if (videoPath != null) {
-// addVideoParameter(PageFactory.getVideoRecorder().getvideoPath());
-// PageFactory.setVideoRecorderToNull();
-// }
-// }
+
+ if (VideoRecorder.getInstance().isVideoStarted()) {
+ String videoPath = VideoRecorder.getInstance().stopRecording();
+ if (videoPath != null) {
+ addVideoParameter(VideoRecorder.getInstance().getVideoPath());
+ VideoRecorder.getInstance().resetVideoRecorder();
+ }
+ }
LOG.debug("TestFailure:" + failure.getTrace());
-
+
takeScreenshot();
-
+
super.testFailure(failure);
}
/**
- * Mark test as Failure for Allure report if test failed, but it was not critical
+ * Mark test as Failure for Allure report if test failed, but it was not
+ * critical
*
* @param description - description of test
* @throws IllegalAccessException TODO
*/
@Override
public void testFinished(Description description) throws IllegalAccessException {
-// if (PageFactory.getVideoRecorder() != null) {
-// addVideoParameter(PageFactory.getVideoRecorder().getvideoPath());
-// }
-
+ addVideoParameter(VideoRecorder.getInstance().getVideoPath());
+
if (AllureNonCriticalFailure.getFailure().containsKey(Thread.currentThread())) {
takeScreenshot();
}
-
+
super.testFinished(description);
}
@@ -57,17 +57,17 @@ public void testFinished(Description description) throws IllegalAccessException
*/
@Override
public void testSuiteFinished(String uid) {
-// if (PageFactory.getVideoRecorder() != null && PageFactory.getVideoRecorder().isVideoStarted()) {
-// String videoPath = PageFactory.getVideoRecorder().stopRecording();
-// if (videoPath != null) {
-// addVideoParameter(PageFactory.getVideoRecorder().getvideoPath());
-// PageFactory.setVideoRecorderToNull();
-// }
-// }
-
+ if (VideoRecorder.getInstance().isVideoStarted()) {
+ String videoPath = VideoRecorder.getInstance().stopRecording();
+ if (videoPath != null) {
+ addVideoParameter(VideoRecorder.getInstance().getVideoPath());
+ VideoRecorder.getInstance().resetVideoRecorder();
+ }
+ }
+
super.testSuiteFinished(uid);
}
-
+
/**
*
*/
diff --git a/src/main/resources/META-INF/aop.xml b/src/main/resources/META-INF/aop.xml
index 3be6391..3e2e6fb 100644
--- a/src/main/resources/META-INF/aop.xml
+++ b/src/main/resources/META-INF/aop.xml
@@ -5,6 +5,6 @@
-
+
\ No newline at end of file