Search in sources :

Example 56 with TestVariable

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

the class TestTestTasks method testUpdateNewVariable.

/**
 * Check upsert of a new variable
 * Verify server is called and configuration is updated according to the new value
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testUpdateNewVariable(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    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);
        TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
        when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        TestTasks.createOrUpdateParam("key", "value");
        // check upsert has been called
        verify(variableServer).upsertVariable(new TestVariable("key", "value"), true);
        // check configuration is updated
        Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getConfiguration().get("key"), varToReturn);
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : ITestResult(org.testng.ITestResult) TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 57 with TestVariable

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

the class TestTestTasks method testUpdateReservableVariableWithTTL.

/**
 * Check that if TTL and reservable is set, all information are passer to server
 * @param testNGCtx
 * @param xmlTest
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testUpdateReservableVariableWithTTL(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
    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);
        TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
        when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
        ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
        initThreadContext(testNGCtx, "myTest", testResult);
        TestTasks.createOrUpdateParam("key", "value", false, 1, true);
        // check upsert has been called
        verify(variableServer).upsertVariable(new TestVariable(null, "key", "value", true, "key", 1, null), false);
    } finally {
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
        System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
    }
}
Also used : ITestResult(org.testng.ITestResult) TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) XmlTest(org.testng.xml.XmlTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 58 with TestVariable

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

the class TestTestVariable method testInterpolateValue.

@Test(groups = { "ut" })
public void testInterpolateValue() {
    SeleniumTestsContextManager.getThreadContext().getConfiguration().put("path", new TestVariable("path", "/foo/bar"));
    Assert.assertEquals(new TestVariable("url", "http://mysite${path}").getValue(), "http://mysite/foo/bar");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 59 with TestVariable

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

the class TestTestVariable method testFromJSon.

/**
 * Test variable without date
 */
@Test(groups = { "ut" })
public void testFromJSon() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("id", 1);
    jsonObject.put("name", "key");
    jsonObject.put("value", "value");
    jsonObject.put("reservable", false);
    jsonObject.put("environment", 1);
    jsonObject.put("application", 2);
    jsonObject.put("version", 3);
    TestVariable var = TestVariable.fromJsonObject(jsonObject);
    Assert.assertEquals(var.getId(), (Integer) 1);
    Assert.assertEquals(var.getName(), "key");
    Assert.assertEquals(var.getValue(), "value");
    Assert.assertEquals(var.isReservable(), false);
    Assert.assertEquals(var.getInternalName(), "key");
    Assert.assertNull(var.getCreationDate());
}
Also used : JSONObject(kong.unirest.json.JSONObject) TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 60 with TestVariable

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

the class TestTestVariable method testFromJSonWithDate.

/**
 * Test variable with date
 */
@Test(groups = { "ut" })
public void testFromJSonWithDate() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("id", 1);
    jsonObject.put("name", "key");
    jsonObject.put("value", "value");
    jsonObject.put("reservable", false);
    jsonObject.put("environment", 1);
    jsonObject.put("application", 2);
    jsonObject.put("version", 3);
    jsonObject.put("creationDate", "2018-07-12T08:42:56.156727Z");
    TestVariable var = TestVariable.fromJsonObject(jsonObject);
    Assert.assertEquals(var.getId(), (Integer) 1);
    Assert.assertEquals(var.getName(), "key");
    Assert.assertEquals(var.getValue(), "value");
    Assert.assertEquals(var.isReservable(), false);
    Assert.assertEquals(var.getInternalName(), "key");
    Assert.assertEquals(var.getCreationDate(), LocalDateTime.of(2018, 7, 12, 8, 42, 56, 156727000));
}
Also used : JSONObject(kong.unirest.json.JSONObject) TestVariable(com.seleniumtests.core.TestVariable) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

TestVariable (com.seleniumtests.core.TestVariable)72 Test (org.testng.annotations.Test)66 GenericTest (com.seleniumtests.GenericTest)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 XmlTest (org.testng.xml.XmlTest)34 ConnectorsTest (com.seleniumtests.ConnectorsTest)19 MockitoTest (com.seleniumtests.MockitoTest)19 ITestResult (org.testng.ITestResult)14 HashMap (java.util.HashMap)13 SeleniumRobotVariableServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SeleniumTestsContext (com.seleniumtests.core.SeleniumTestsContext)7 File (java.io.File)3 ArrayList (java.util.ArrayList)3 JSONObject (kong.unirest.json.JSONObject)3 BrowserExtension (com.seleniumtests.browserfactory.BrowserExtension)2 ConfigReader (com.seleniumtests.core.config.ConfigReader)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 IOException (java.io.IOException)2 HttpRequest (kong.unirest.HttpRequest)2