Search in sources :

Example 66 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class Table method getCellFromContent.

/**
 * Returns the cell from table, searching for its content by pattern
 *
 * Tip: returned element is a HtmlElement, but you must cast it to use its specific methods
 *
 * @param content	pattern to search for
 * @param column	column where pattern should be searched
 * @return
 */
@ReplayOnError
public WebElement getCellFromContent(final Pattern content, final int column) {
    findTableElement();
    if (rows != null && !rows.isEmpty()) {
        for (WebElement row : rows) {
            List<WebElement> cols = getRowCells(row);
            if (cols.isEmpty()) {
                throw new ScenarioException("There are no columns in this row");
            }
            WebElement cell = cols.get(column);
            Matcher matcher = content.matcher(cell.getText());
            if (matcher.matches()) {
                return cell;
            }
        }
        throw new ScenarioException(String.format("Pattern %s has not been found in table", content.pattern()));
    } else {
        throw new ScenarioException(ERROR_NO_ROWS);
    }
}
Also used : Matcher(java.util.regex.Matcher) WebElement(org.openqa.selenium.WebElement) ScenarioException(com.seleniumtests.customexception.ScenarioException) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 67 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class TestSquashTMApi method testCannotAddTestCaseDoesNotExist.

/**
 * Check exception is raised if test case does not exist
 */
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class)
public void testCannotAddTestCaseDoesNotExist() {
    PowerMockito.when(Project.getAll()).thenReturn(Arrays.asList(project1, project2));
    SquashTMApi api = new SquashTMApi("http://localhost:4321", "user", "password", "project1");
    doReturn(Arrays.asList(testPlanItem1, testPlanItem2)).when(iteration1).getAllTestCases();
    PowerMockito.doThrow(new ScenarioException("")).when(TestCase.class);
    TestCase.get(3);
    doReturn(testPlanItem1).when(iteration1).addTestCase(any(TestCase.class));
    IterationTestPlanItem itpi = api.addTestCaseInIteration(iteration1, 3);
}
Also used : SquashTMApi(com.seleniumtests.connectors.tms.squash.SquashTMApi) IterationTestPlanItem(com.seleniumtests.connectors.tms.squash.entities.IterationTestPlanItem) TestCase(com.seleniumtests.connectors.tms.squash.entities.TestCase) ScenarioException(com.seleniumtests.customexception.ScenarioException) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 68 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class TestSquashTMConnector method testNoExceptionWhenErrorInRecording.

/**
 * Check that if any error occurs during result recording, it does not raise any exception, only message will be displayed
 * @param testContext
 */
@Test(groups = { "ut" })
public void testNoExceptionWhenErrorInRecording(ITestContext testContext) {
    JSONObject connect = new JSONObject();
    connect.put(SquashTMConnector.TMS_SERVER_URL, "http://myServer");
    connect.put(SquashTMConnector.TMS_PROJECT, "project");
    connect.put(SquashTMConnector.TMS_USER, "user");
    connect.put(SquashTMConnector.TMS_PASSWORD, "password");
    SquashTMConnector squash = spy(new SquashTMConnector());
    squash.init(connect);
    doReturn(api).when(squash).getApi();
    CustomAttribute testIdAttr = new CustomAttribute() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return null;
        }

        @Override
        public String[] values() {
            return new String[] { "1" };
        }

        @Override
        public String name() {
            return "testId";
        }
    };
    // customize test result so that it has attributes
    when(testResult.getMethod()).thenReturn(testMethod);
    when(testResult.isSuccess()).thenReturn(true);
    when(testResult.getName()).thenReturn("MyTest");
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getParameters()).thenReturn(new Object[] {});
    when(testResult.getAttribute("testContext")).thenReturn(SeleniumTestsContextManager.getThreadContext());
    when(testMethod.getAttributes()).thenReturn(new CustomAttribute[] { testIdAttr });
    when(api.createCampaign(anyString(), anyString())).thenThrow(new ScenarioException("Something went wrong"));
    when(api.createIteration(any(Campaign.class), anyString())).thenReturn(iteration);
    when(api.addTestCaseInIteration(iteration, 1)).thenReturn(iterationTestPlanItem);
    squash.recordResult(testResult);
    // check we do not call API as testId is not provided
    verify(api).createCampaign("Selenium " + testContext.getName(), "");
    verify(api, never()).createIteration(campaign, SeleniumTestsContextManager.getThreadContext().getApplicationVersion());
    verify(api, never()).addTestCaseInIteration(iteration, 1);
    verify(api, never()).setExecutionResult(iterationTestPlanItem, ExecutionStatus.SUCCESS);
}
Also used : Campaign(com.seleniumtests.connectors.tms.squash.entities.Campaign) JSONObject(org.json.JSONObject) CustomAttribute(org.testng.annotations.CustomAttribute) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SquashTMConnector(com.seleniumtests.connectors.tms.squash.SquashTMConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

ScenarioException (com.seleniumtests.customexception.ScenarioException)68 ArrayList (java.util.ArrayList)17 WebElement (org.openqa.selenium.WebElement)14 UnirestException (kong.unirest.UnirestException)13 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)12 IOException (java.io.IOException)12 JSONObject (kong.unirest.json.JSONObject)12 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)11 Element (com.seleniumtests.uipage.htmlelements.Element)11 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)11 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)11 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)11 File (java.io.File)10 List (java.util.List)9 HashMap (java.util.HashMap)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 AWTException (java.awt.AWTException)7 Robot (java.awt.Robot)6 Map (java.util.Map)5 TestStep (com.seleniumtests.reporter.logger.TestStep)4