Search in sources :

Example 31 with TestAction

use of com.seleniumtests.reporter.logger.TestAction in project seleniumRobot by bhecquet.

the class TestLogActions method testSubStepsNonCucumberStepLogging.

/**
 * Check presence of sub steps. These are methods defined in Page object but not directly called from main test. We should get
 * - page opening
 * - add(1, 1)
 * 		- nothing
 * 			- doNothing on HtmlElement none
 * - add(2)											=> step
 * 		- add (2, 2)								=> sub-step
 * 			- donothing								=> sub-step
 * 				- doNothing on HtmlElement none		=> action on element
 * Checks that root steps are correctly intercepted
 * @throws IOException
 */
@Test(groups = { "it" })
public void testSubStepsNonCucumberStepLogging() throws IOException {
    new CalcPage().add(1, 1).add(2);
    List<TestStep> steps = SeleniumTestsContextManager.getThreadContext().getTestStepManager().getTestSteps();
    Assert.assertEquals(steps.size(), 3);
    Assert.assertEquals(steps.get(0).getName(), "openPage with args: (null, )");
    Assert.assertEquals(steps.get(1).getName(), "add with args: (1, 1, )");
    Assert.assertEquals(steps.get(2).getName(), "add with args: (2, )");
    Assert.assertEquals(steps.get(1).getStepActions().size(), 1);
    TestStep subStep = (TestStep) steps.get(1).getStepActions().get(0);
    Assert.assertEquals(subStep.getStepActions().size(), 1);
    Assert.assertEquals(subStep.getName(), "doNothing ");
    TestAction subSubAction = subStep.getStepActions().get(0);
    Assert.assertEquals(subSubAction.getName(), "doNothing on HtmlElement none, by={By.id: none} ");
    Assert.assertEquals(steps.get(2).getStepActions().size(), 1);
    subStep = (TestStep) steps.get(2).getStepActions().get(0);
    Assert.assertEquals(subStep.getStepActions().size(), 1);
    Assert.assertEquals(subStep.getName(), "add with args: (2, 2, )");
    TestStep subSubStep = (TestStep) subStep.getStepActions().get(0);
    Assert.assertEquals(subSubStep.getName(), "doNothing ");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 32 with TestAction

use of com.seleniumtests.reporter.logger.TestAction in project seleniumRobot by bhecquet.

the class StubTestClass method testInError.

@Test(groups = "stub")
public void testInError() {
    TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    TestStepManager.setCurrentRootTestStep(step1);
    TestStepManager.getParentTestStep().addAction(new TestAction("click button", false, new ArrayList<>()));
    TestStepManager.getParentTestStep().addMessage(new TestMessage("click ok", MessageType.INFO));
    logger.warn("Some warning message");
    logger.info("Some Info message");
    logger.error("Some Error message");
    ((ScenarioLogger) logger).log("Some log message");
    ((ScenarioLogger) logger).logTestValue("key", "we found a value of", "10");
    TestStepManager.getParentTestStep().addAction(new TestAction("send keyboard action", false, new ArrayList<>()));
    TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
    Assert.fail("error");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger) TestMessage(com.seleniumtests.reporter.logger.TestMessage) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test)

Example 33 with TestAction

use of com.seleniumtests.reporter.logger.TestAction in project seleniumRobot by bhecquet.

the class StubTestClass method testWithException2.

/**
 * An other test that throws exception
 */
@Test(groups = "stub", dependsOnMethods = "testAndSubActions")
public void testWithException2() {
    TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    step1.addAction(new TestAction(String.format("played %d times", count), false, new ArrayList<>()));
    step1.addAction(new TestAction("click button", false, new ArrayList<>()));
    TestStepManager.logTestStep(step1);
    throw new DriverExceptions("some exception");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) ArrayList(java.util.ArrayList) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test)

Example 34 with TestAction

use of com.seleniumtests.reporter.logger.TestAction in project seleniumRobot by bhecquet.

the class StubTestClass method testWithSocketTimeoutOnFirstExec.

/**
 * Test which fails only on first execution
 */
@Test(groups = "stub")
public void testWithSocketTimeoutOnFirstExec() {
    TestStep step1 = new TestStep("step 10", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    step1.addAction(new TestAction(String.format("played %d times", count), false, new ArrayList<>()));
    step1.addAction(new TestAction("click button", false, new ArrayList<>()));
    TestStepManager.logTestStep(step1);
    if (!failed) {
        failed = true;
        throw new WebDriverException("Session [6919ba25-53b6-4615-bd59-e97399bf1e12] was terminated due to SO_TIMEOUT");
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) TestAction(com.seleniumtests.reporter.logger.TestAction) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test)

Example 35 with TestAction

use of com.seleniumtests.reporter.logger.TestAction in project seleniumRobot by bhecquet.

the class StubTestClass method testAndSubActions.

@Test(groups = "stub", description = "a test with steps")
public void testAndSubActions() throws IOException {
    TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    step1.addAction(new TestAction("click button", false, new ArrayList<>()));
    step1.addAction(new TestAction("sendKeys to text field", true, new ArrayList<>()));
    File tmpImg = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
    File tmpHtml = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");
    ScreenShot screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + tmpImg.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
    ScreenShot screenshot2 = new ScreenShot();
    screenshot2.setImagePath("screenshot/" + tmpImg.getName());
    screenshot2.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.moveFile(tmpImg, new File(screenshot2.getFullImagePath()));
    FileUtils.moveFile(tmpHtml, new File(screenshot2.getFullHtmlPath()));
    step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.FULL), 1, null);
    step1.setActionException(new WebDriverException("driver exception"));
    TestStep subStep1 = new TestStep("step 1.3: open page", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    subStep1.addAction(new TestAction("click link", false, new ArrayList<>()));
    subStep1.addMessage(new TestMessage("a message", MessageType.LOG));
    subStep1.addAction(new TestAction("sendKeys to password field", false, new ArrayList<>()));
    step1.addAction(subStep1);
    WaitHelper.waitForSeconds(3);
    step1.setDuration(1230L);
    TestStep step2 = new TestStep("step 2", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    step2.setDuration(14030L);
    TestStepManager.logTestStep(step1);
    TestStepManager.logTestStep(step2);
    tmpImg.deleteOnExit();
    tmpHtml.deleteOnExit();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) TestMessage(com.seleniumtests.reporter.logger.TestMessage) File(java.io.File) TestAction(com.seleniumtests.reporter.logger.TestAction) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test)

Aggregations

TestAction (com.seleniumtests.reporter.logger.TestAction)56 TestStep (com.seleniumtests.reporter.logger.TestStep)47 Test (org.testng.annotations.Test)44 ArrayList (java.util.ArrayList)38 GenericTest (com.seleniumtests.GenericTest)24 TestMessage (com.seleniumtests.reporter.logger.TestMessage)12 DriverExceptions (com.seleniumtests.customexception.DriverExceptions)8 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)5 Snapshot (com.seleniumtests.reporter.logger.Snapshot)5 File (java.io.File)5 HashMap (java.util.HashMap)5 GenericFile (com.seleniumtests.reporter.logger.GenericFile)3 Element (org.jdom2.Element)3 WebDriverException (org.openqa.selenium.WebDriverException)3 HarCapture (com.seleniumtests.reporter.logger.HarCapture)2 PageObject (com.seleniumtests.uipage.PageObject)2 Instant (java.time.Instant)2 Har (net.lightbody.bmp.core.har.Har)2 HarLog (net.lightbody.bmp.core.har.HarLog)2 HarPage (net.lightbody.bmp.core.har.HarPage)2