Search in sources :

Example 6 with SeleniumTestsContext

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

the class TestAndroidCapabilitiesFactory method testCreateCapabilitiesWithRelativeApplicationPath.

/**
 * Check mobile test with app relative path => check absolute path is set in capabilities
 */
@Test(groups = { "ut" })
public void testCreateCapabilitiesWithRelativeApplicationPath() {
    SeleniumTestsContext context = new SeleniumTestsContext(SeleniumTestsContextManager.getThreadContext());
    context.setMobilePlatformVersion("8.0");
    context.setPlatform("android");
    context.setDeviceName("Samsung Galasy S8");
    context.setAppPackage("appPackage");
    context.setAppActivity("appActivity");
    context.setApp("data/core/app.apk");
    DriverConfig config = new DriverConfig(context);
    AndroidCapabilitiesFactory capaFactory = new AndroidCapabilitiesFactory(config);
    MutableCapabilities capa = capaFactory.createCapabilities();
    Assert.assertEquals(capa.getCapability(CapabilityType.BROWSER_NAME), "");
    logger.info("app path: " + capa.getCapability("app"));
    Assert.assertTrue(capa.getCapability("app").toString().contains("/data/core/app.apk"));
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) MutableCapabilities(org.openqa.selenium.MutableCapabilities) DriverConfig(com.seleniumtests.driver.DriverConfig) AndroidCapabilitiesFactory(com.seleniumtests.browserfactory.AndroidCapabilitiesFactory) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 7 with SeleniumTestsContext

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

the class TestAndroidCapabilitiesFactory method testCreateCapabilitiesWithAbsoluteApplicationPath.

/**
 * Check mobile test with app relative path => check absolute path is set in capabilities
 */
@Test(groups = { "ut" })
public void testCreateCapabilitiesWithAbsoluteApplicationPath() {
    SeleniumTestsContext context = new SeleniumTestsContext(SeleniumTestsContextManager.getThreadContext());
    context.setMobilePlatformVersion("8.0");
    context.setPlatform("android");
    context.setDeviceName("Samsung Galasy S8");
    context.setAppPackage("appPackage");
    context.setAppActivity("appActivity");
    String path = new File("data/core/app.apk").getAbsolutePath();
    context.setApp(path);
    DriverConfig config = new DriverConfig(context);
    AndroidCapabilitiesFactory capaFactory = new AndroidCapabilitiesFactory(config);
    MutableCapabilities capa = capaFactory.createCapabilities();
    Assert.assertEquals(capa.getCapability(CapabilityType.BROWSER_NAME), "");
    Assert.assertEquals(capa.getCapability("app"), path.replace("\\", "/"));
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) MutableCapabilities(org.openqa.selenium.MutableCapabilities) DriverConfig(com.seleniumtests.driver.DriverConfig) File(java.io.File) AndroidCapabilitiesFactory(com.seleniumtests.browserfactory.AndroidCapabilitiesFactory) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 8 with SeleniumTestsContext

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

the class TestAndroidCapabilitiesFactory method testCreateCapabilitiesWithApplicationOldAndroid.

/**
 * Check automationName capability with android < 4
 */
@Test(groups = { "ut" })
public void testCreateCapabilitiesWithApplicationOldAndroid() {
    SeleniumTestsContext context = new SeleniumTestsContext(SeleniumTestsContextManager.getThreadContext());
    context.setMobilePlatformVersion("2.3");
    context.setPlatform("android");
    context.setDeviceName("Samsung Galasy S1");
    context.setAppPackage("appPackage");
    context.setAppActivity("appActivity");
    context.setFullReset(true);
    context.setApp("com.covea.mobileapp");
    DriverConfig config = new DriverConfig(context);
    AndroidCapabilitiesFactory capaFactory = new AndroidCapabilitiesFactory(config);
    MutableCapabilities capa = capaFactory.createCapabilities();
    Assert.assertEquals(capa.getCapability(MobileCapabilityType.AUTOMATION_NAME), "Selendroid");
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) MutableCapabilities(org.openqa.selenium.MutableCapabilities) DriverConfig(com.seleniumtests.driver.DriverConfig) AndroidCapabilitiesFactory(com.seleniumtests.browserfactory.AndroidCapabilitiesFactory) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 9 with SeleniumTestsContext

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

the class TestSeleniumTestContext3 method testGridConnectorIsCopiedWithContextCopy.

/**
 * issue #291: Check that when copying context, grid connector is also copied so
 * that it can be possible to re-use a driver created in \@BeforeMethod
 *
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testGridConnectorIsCopiedWithContextCopy(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    Map<String, TestVariable> variables = new HashMap<>();
    variables.put("key", new TestVariable("key", "val1"));
    try {
        System.setProperty(SeleniumTestsContext.WEB_DRIVER_GRID, "http://localhost:4321/wd/hub");
        System.setProperty(SeleniumTestsContext.RUN_MODE, "grid");
        System.setProperty(SeleniumTestsContext.BROWSER, "chrome");
        createGridHubMockWithNodeOK();
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        seleniumTestsCtx.configureContext(testResult);
        WebUIDriver.getWebDriver(true);
        // do a parameter retrieving for copied context
        SeleniumTestsContext seleniumTestsCtx2 = new SeleniumTestsContext(seleniumTestsCtx, false);
        Assert.assertEquals(seleniumTestsCtx2.getSeleniumGridConnector(), seleniumTestsCtx.getSeleniumGridConnector());
    } finally {
        System.clearProperty(SeleniumTestsContext.WEB_DRIVER_GRID);
        System.clearProperty(SeleniumTestsContext.RUN_MODE);
        System.clearProperty(SeleniumTestsContext.BROWSER);
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) HashMap(java.util.HashMap) TestVariable(com.seleniumtests.core.TestVariable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

Example 10 with SeleniumTestsContext

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

the class TestSeleniumTestContext3 method testVariablesFromVariableServer.

/**
 * Check variables can be get from variable server
 *
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testVariablesFromVariableServer(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    Map<String, TestVariable> variables = new HashMap<>();
    variables.put("key1", new TestVariable("key1", "val1"));
    try {
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
        System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
        PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
        when(variableServer.isAlive()).thenReturn(true);
        when(variableServer.getVariables(0)).thenReturn(variables);
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        SeleniumTestsContext seleniumTestsCtx = SeleniumTestsContextManager.getThreadContext();
        seleniumTestsCtx.configureContext(testResult);
        Assert.assertEquals(seleniumTestsCtx.getConfiguration().get("key1").getValue(), "val1");
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : SeleniumTestsContext(com.seleniumtests.core.SeleniumTestsContext) ITestResult(org.testng.ITestResult) HashMap(java.util.HashMap) TestVariable(com.seleniumtests.core.TestVariable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest)

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