use of com.seleniumtests.uipage.PageObject in project seleniumRobot by bhecquet.
the class LogAction method logPageObjectAction.
/**
* Intercept actions and log them only if a step is already defined
* @param joinPoint
* @throws Throwable
*/
@Around("execution(public * com.seleniumtests.uipage.PageObject..* (..)) " + "&& !execution(* com.seleniumtests.uipage.PageObject.get* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.close* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.param (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.assert* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.addStep* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.capture*Snapshot (..))")
public Object logPageObjectAction(ProceedingJoinPoint joinPoint) throws Throwable {
PageObject page = (PageObject) joinPoint.getTarget();
String pageName = page == null ? "" : "on page " + page.getClass().getSimpleName();
return logAction(joinPoint, pageName);
}
use of com.seleniumtests.uipage.PageObject in project seleniumRobot by bhecquet.
the class TestPageObject2 method testChangePage.
@Test(groups = { "ut" })
public void testChangePage() throws IOException {
PageObject nextPage = page.changeToPage(PageForActions.class);
Assert.assertNotEquals(page, nextPage);
}
use of com.seleniumtests.uipage.PageObject in project seleniumRobot by bhecquet.
the class LogAction method commonLogTestStep.
/**
* Log a TestStep, inside a parent TestStep or not
* Common method used for all test step logging
* @return
* @throws Throwable
*/
private Object commonLogTestStep(ProceedingJoinPoint joinPoint, String stepNamePrefix, boolean configStep) throws Throwable {
Object reply = null;
boolean rootStep = false;
TestStep previousParent = null;
// step name will contain method arguments only if it's not a configuration method (as they are generic)
TestStep currentStep = buildRootStep(joinPoint, stepNamePrefix, !configStep);
if ("openPage".equals(joinPoint.getSignature().getName()) && joinPoint.getTarget() instanceof PageObject) {
PageObject page = (PageObject) joinPoint.getTarget();
currentStep.addAction(new TestAction(String.format("Opening page %s", page.getClass().getSimpleName()), false, new ArrayList<>()));
}
BrowserMobProxy mobProxy = WebUIDriver.getBrowserMobProxy();
NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver();
VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
// if rootStep is null, parent step is also null
if (TestStepManager.getCurrentRootTestStep() == null) {
// will also set parent step
TestStepManager.setCurrentRootTestStep(currentStep);
rootStep = true;
if (mobProxy != null) {
mobProxy.newPage(currentStep.getName());
}
if (videoRecorder != null) {
CustomEventFiringWebDriver.displayStepOnScreen(currentStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
}
if (neoloadDriver != null) {
neoloadDriver.startTransaction(currentStep.getName());
}
} else {
TestStepManager.getParentTestStep().addStep(currentStep);
previousParent = TestStepManager.getParentTestStep();
TestStepManager.setParentTestStep(currentStep);
}
// set the start date once step is initialized so that when we get the video frame associated to step, step name displayed on screen is the same as the running step name
currentStep.setStartDate();
try {
reply = joinPoint.proceed(joinPoint.getArgs());
} catch (Throwable e) {
currentStep.setFailed(true);
currentStep.setActionException(e);
// issue #287 (https://github.com/cbeust/testng/issues/2148): is method an @AfterMethod. Then do not rethrow exception
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
if (methodSignature.getMethod().getAnnotation(AfterMethod.class) != null) {
scenarioLogger.error(String.format("Error in @AfterMethod %s: %s", methodSignature, e.getMessage()));
} else {
throw e;
}
} finally {
if (rootStep) {
TestStepManager.getCurrentRootTestStep().updateDuration();
TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
if (neoloadDriver != null) {
neoloadDriver.stopTransaction();
}
} else {
TestStepManager.setParentTestStep(previousParent);
}
}
return reply;
}
use of com.seleniumtests.uipage.PageObject in project seleniumRobot by bhecquet.
the class TestPageObject2 method testClickTo.
@Test(groups = { "ut" })
public void testClickTo() throws IOException {
when(driver.findElement(By.id("text"))).thenReturn(element);
PageObject nextPage = page.clickAndChangeToPage("textField", PageForActions.class);
verify(element).click();
Assert.assertNotEquals(page, nextPage);
}
use of com.seleniumtests.uipage.PageObject in project seleniumRobot by bhecquet.
the class TestPageObject2 method testClick.
@Test(groups = { "ut" })
public void testClick() throws IOException {
when(driver.findElement(By.id("text"))).thenReturn(element);
PageObject nextPage = page.click("textField");
verify(element).click();
Assert.assertEquals(page, nextPage);
}
Aggregations