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);
}
}
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);
}
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);
}
Aggregations