Search in sources :

Example 1 with BaseActionLoader

use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.

the class ModifySahiTimerAspect method modifySahiTimer.

void modifySahiTimer(JoinPoint joinPoint, boolean beforeMethod) {
    BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
    SahiProxyProperties sahiProxyProperties = loader.getSahiProxyProperties();
    if (sahiProxyProperties != null && sahiProxyProperties.isRequestDelayActive()) {
        RhinoScriptRunner rhinoScriptRunner = loader.getRhinoScriptRunner();
        if (rhinoScriptRunner != null && rhinoScriptRunner.getSession() != null) {
            getLogger(joinPoint).debug("MODIFY SAHI-TIMER for {}", getClassAndMethodAsString(joinPoint));
            Session session = rhinoScriptRunner.getSession();
            if (beforeMethod) {
                Integer delay = determineDelay(joinPoint, loader);
                session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, delay.toString());
                //short sleep to ensure that browser context can read out the value
                try {
                    logger.info("wait {}ms for sahi refresh", sahiProxyProperties.getRequestDelayRefreshMs());
                    Thread.sleep(sahiProxyProperties.getRequestDelayRefreshMs());
                } catch (InterruptedException e) {
                    BeanLoader.loadBaseActionLoader().getExceptionHandler().handleException(e, true);
                }
                logger.info("sahi-proxy-timer modified to {} ms", delay.toString());
            } else {
                logger.info("reset sahi-proxy-timer");
                session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
            }
        }
    }
}
Also used : RhinoScriptRunner(net.sf.sahi.rhino.RhinoScriptRunner) BaseActionLoader(org.sakuli.loader.BaseActionLoader) SahiProxyProperties(org.sakuli.datamodel.properties.SahiProxyProperties) Session(net.sf.sahi.session.Session)

Example 2 with BaseActionLoader

use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.

the class ModifySahiTimerAspectTest method testDetermineDelay.

@Test
public void testDetermineDelay() throws Exception {
    BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
    when(loader.getSahiProxyProperties().getRequestDelayMs()).thenReturn(500);
    loader.getActionProperties().setTypeDelay(0.05);
    JoinPoint joinPoint = mock(JoinPoint.class);
    Signature signature = mock(Signature.class);
    when(joinPoint.getSignature()).thenReturn(signature);
    when(signature.getName()).thenReturn("pasteSomething");
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 500);
    when(signature.getName()).thenReturn("typeMasked");
    when(joinPoint.getArgs()).thenReturn(new String[] { "1", "MOD" });
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 550);
    when(joinPoint.getArgs()).thenReturn(new String[] { "12characters", "MOD" });
    assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 12 * 550);
}
Also used : Signature(org.aspectj.lang.Signature) BaseActionLoader(org.sakuli.loader.BaseActionLoader) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 3 with BaseActionLoader

use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.

the class ModifySahiTimerAspectTest method testDisabledModifySahiTimer.

@Test
public void testDisabledModifySahiTimer() throws Exception {
    RhinoScriptRunner runner = mock(RhinoScriptRunner.class);
    Session session = mock(Session.class);
    when(runner.getSession()).thenReturn(session);
    BaseActionLoader baseActionLoader = BeanLoader.loadBaseActionLoader();
    baseActionLoader.setRhinoScriptRunner(runner);
    when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(false);
    doReturn(LoggerFactory.getLogger(this.getClass())).when(testling).getLogger(any(JoinPoint.class));
    doReturn("sig.method()").when(testling).getClassAndMethodAsString(any(JoinPoint.class));
    //test modifcation of timer is disabled
    testling.modifySahiTimer(mock(JoinPoint.class), true);
    testling.modifySahiTimer(mock(JoinPoint.class), false);
    verify(session, never()).setVariable(anyString(), anyString());
    verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
    //test no session available
    when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(true);
    when(runner.getSession()).thenReturn(null);
    testling.modifySahiTimer(mock(JoinPoint.class), true);
    testling.modifySahiTimer(mock(JoinPoint.class), false);
    verify(session, never()).setVariable(anyString(), anyString());
    verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
}
Also used : RhinoScriptRunner(net.sf.sahi.rhino.RhinoScriptRunner) BaseActionLoader(org.sakuli.loader.BaseActionLoader) Session(net.sf.sahi.session.Session) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 4 with BaseActionLoader

use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.

the class ModifySahiTimerAspectTest method testModifySahiTimer.

@Test
public void testModifySahiTimer() throws Exception {
    RhinoScriptRunner runner = mock(RhinoScriptRunner.class);
    Session session = mock(Session.class);
    when(runner.getSession()).thenReturn(session);
    BaseActionLoader baseActionLoader = BeanLoader.loadBaseActionLoader();
    baseActionLoader.setRhinoScriptRunner(runner);
    when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(true);
    doReturn(1000).when(testling).determineDelay(any(JoinPoint.class), any(BaseActionLoader.class));
    doReturn(LoggerFactory.getLogger(this.getClass())).when(testling).getLogger(any(JoinPoint.class));
    doReturn("sig.method()").when(testling).getClassAndMethodAsString(any(JoinPoint.class));
    //test modifcation of timer to 1000ms
    testling.modifySahiTimer(mock(JoinPoint.class), true);
    verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, "1000");
    verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
    assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "sahi-proxy-timer modified to 1000 ms");
    //test reset timer
    testling.modifySahiTimer(mock(JoinPoint.class), false);
    verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
    verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
    assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "reset sahi-proxy-timer");
}
Also used : RhinoScriptRunner(net.sf.sahi.rhino.RhinoScriptRunner) BaseActionLoader(org.sakuli.loader.BaseActionLoader) Session(net.sf.sahi.session.Session) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 5 with BaseActionLoader

use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.

the class RhinoAspectTest method testDoTestCaseActionLog.

@Test
public void testDoTestCaseActionLog() throws Exception {
    initMocks();
    BaseActionLoader loader = mock(BaseActionLoader.class);
    TestCase sampleTc = new TestCase("test", "testID");
    when(loader.getCurrentTestCase()).thenReturn(sampleTc);
    TestCaseAction testAction = new TestCaseAction();
    ReflectionTestUtils.setField(testAction, "loader", loader, BaseActionLoader.class);
    testAction.init("testID", 3, 4, "imagefolder1", "imagefolder2");
    assertLastLine(logFile, testAction.getClass().getSimpleName(), LogLevel.INFO, "\"test case [" + sampleTc.getActionValueString() + "]\" TestCaseAction.init() - init a new test case with arg(s) [testID, 3, 4, [imagefolder1, imagefolder2]]");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TestCaseAction(org.sakuli.actions.TestCaseAction) BaseActionLoader(org.sakuli.loader.BaseActionLoader) Test(org.testng.annotations.Test)

Aggregations

BaseActionLoader (org.sakuli.loader.BaseActionLoader)5 Test (org.testng.annotations.Test)4 RhinoScriptRunner (net.sf.sahi.rhino.RhinoScriptRunner)3 Session (net.sf.sahi.session.Session)3 JoinPoint (org.aspectj.lang.JoinPoint)3 Signature (org.aspectj.lang.Signature)1 TestCaseAction (org.sakuli.actions.TestCaseAction)1 TestCase (org.sakuli.datamodel.TestCase)1 SahiProxyProperties (org.sakuli.datamodel.properties.SahiProxyProperties)1