Search in sources :

Example 51 with SeleniumTestsContext

use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.

the class TestSeleniumTestContext method testUndefinedParamOverride.

/**
 * Check that unknown parameters in test override the same param in test suite
 */
@Test(groups = { "ut context" })
public void testUndefinedParamOverride(final ITestContext testNGCtx, final XmlTest xmlTest) {
    initThreadContext(testNGCtx);
    SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
    Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("anOtherParam").getValue(), "value3");
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 52 with SeleniumTestsContext

use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.

the class TestSeleniumTestContext method testPlatformParsingForAndroidFromTest.

/**
 * Same test as above except that platform is set on test level, not in system property
 * @param testNGCtx
 * @param xmlTest
 */
@Test(groups = { "ut context" })
public void testPlatformParsingForAndroidFromTest(final ITestContext testNGCtx, final XmlTest xmlTest) {
    try {
        xmlTest.addParameter("platform", "Android 5.0");
        System.setProperty("deviceName", "");
        initThreadContext(testNGCtx);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        Assert.assertEquals(seleniumTestsCtx.getPlatform(), "Android");
        Assert.assertEquals(seleniumTestsCtx.getMobilePlatformVersion(), "5.0");
    } finally {
        xmlTest.getLocalParameters().remove("platform");
        System.clearProperty("deviceName");
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 53 with SeleniumTestsContext

use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.

the class TestSeleniumTestContext method testTechnicalParameterIsNotAddedToVariables.

@Test(groups = { "ut context" })
public void testTechnicalParameterIsNotAddedToVariables(final ITestContext testNGCtx) {
    try {
        System.setProperty("browser", "safari");
        initThreadContext(testNGCtx);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        Assert.assertNull(seleniumTestsCtx.getConfiguration().get("browser"));
    } finally {
        System.clearProperty("browser");
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) Test(org.testng.annotations.Test) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 54 with SeleniumTestsContext

use of com.seleniumtests.core.SeleniumTestsContext in project seleniumRobot by bhecquet.

the class TestTestNGResultUtil method testChangeTestResultWithSnapshot.

private void testChangeTestResultWithSnapshot(String snapshotName, SnapshotCheckType snapshotCheckType, SnapshotComparisonResult comparisonResult) throws IOException {
    // create a step with snapshot that should be compared
    TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), true);
    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, snapshotName, snapshotCheckType), 1, null);
    SeleniumTestsContext context = SeleniumTestsContextManager.getThreadContext();
    context.getTestStepManager().logTestStep(step1);
    when(testResult.getStatus()).thenReturn(ITestResult.SUCCESS);
    when(testResult.getAttribute("testContext")).thenReturn(context);
    // make this test successful, it will be changed to failed
    List<ITestNGMethod> methods = new ArrayList<>();
    methods.add(testNGMethod);
    when(passedTests.getAllMethods()).thenReturn(methods);
    // be sure we will do comparison
    SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerCompareSnapshotBehaviour("changeTestResult");
    SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerActive(true);
    SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerCompareSnapshot(true);
    PowerMockito.when(SeleniumRobotSnapshotServerConnector.getInstance()).thenReturn(snapshotServerConnector);
    when(snapshotServerConnector.checkSnapshotHasNoDifferences(any(Snapshot.class), anyString(), anyString())).thenReturn(comparisonResult);
    TestNGResultUtils.changeTestResultWithSnapshotComparison(testResult);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ITestNGMethod(org.testng.ITestNGMethod) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)54 Test (org.testng.annotations.Test)44 GenericTest (com.seleniumtests.GenericTest)43 XmlTest (org.testng.xml.XmlTest)32 ITestResult (org.testng.ITestResult)12 AndroidCapabilitiesFactory (com.seleniumtests.browserfactory.AndroidCapabilitiesFactory)11 DriverConfig (com.seleniumtests.driver.DriverConfig)11 MutableCapabilities (org.openqa.selenium.MutableCapabilities)11 HashMap (java.util.HashMap)9 TestVariable (com.seleniumtests.core.TestVariable)7 ConnectorsTest (com.seleniumtests.ConnectorsTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 TestStep (com.seleniumtests.reporter.logger.TestStep)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 ITestContext (org.testng.ITestContext)4 IOException (java.io.IOException)3 Map (java.util.Map)3