Search in sources :

Example 1 with PageObject

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);
}
Also used : PageObject(com.seleniumtests.uipage.PageObject) Around(org.aspectj.lang.annotation.Around)

Example 2 with PageObject

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);
}
Also used : PageObject(com.seleniumtests.uipage.PageObject) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with PageObject

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;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) MethodSignature(org.aspectj.lang.reflect.MethodSignature) NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) ArrayList(java.util.ArrayList) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) PageObject(com.seleniumtests.uipage.PageObject) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) PageObject(com.seleniumtests.uipage.PageObject) TestAction(com.seleniumtests.reporter.logger.TestAction)

Example 4 with PageObject

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);
}
Also used : PageObject(com.seleniumtests.uipage.PageObject) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with PageObject

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);
}
Also used : PageObject(com.seleniumtests.uipage.PageObject) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PageObject (com.seleniumtests.uipage.PageObject)5 MockitoTest (com.seleniumtests.MockitoTest)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 NLWebDriver (com.neotys.selenium.proxies.NLWebDriver)1 TestAction (com.seleniumtests.reporter.logger.TestAction)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 VideoRecorder (com.seleniumtests.util.video.VideoRecorder)1 ArrayList (java.util.ArrayList)1 BrowserMobProxy (net.lightbody.bmp.BrowserMobProxy)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1