Search in sources :

Example 31 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepNoErrors.

/**
 * no error message in the page, no cause should be found
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepNoErrors() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
    PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
    List<Label> labels = new ArrayList<>();
    labels.add(new Label(0, 100, 20, 50, "tout roule"));
    labels.add(new Label(0, 100, 100, 120, "everything is fine"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", "field"));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenReturn(fields);
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 0);
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 32 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepDetectedErrorField.

/**
 * In case an error_field is found, check we show it as an error
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepDetectedErrorField() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
    PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
    List<Label> labels = new ArrayList<>();
    labels.add(new Label(0, 100, 20, 50, "ok"));
    labels.add(new Label(0, 100, 100, 120, "nothing"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", ErrorCauseFinder.CLASS_ERROR_FIELD));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenReturn(fields);
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 1);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_IN_FIELD);
    Assert.assertEquals(causes.get(0).getDescription(), "At least one field in error");
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 33 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepErrorMessageWithException.

/**
 * Check error is only logged when something goes wrong while analyzing picture
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessageWithException() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
    PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
    List<Label> labels = new ArrayList<>();
    labels.add(new Label(0, 100, 20, 50, "il y a eu un gros problème"));
    labels.add(new Label(0, 100, 100, 120, "some error"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", "field"));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenThrow(new ConfigurationException("error"));
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 0);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 34 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestErrorCauseFinder method testSearchInLastStepErrorMessage.

/**
 * Check error causes are found with various error messages
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testSearchInLastStepErrorMessage() throws Exception {
    ITestResult testResult = Reporter.getCurrentTestResult();
    TestNGResultUtils.setSeleniumRobotTestContext(testResult, SeleniumTestsContextManager.getThreadContext());
    SeleniumTestsContextManager.getThreadContext().getTestStepManager().setTestSteps(Arrays.asList(step1, lastStep));
    PowerMockito.whenNew(ImageFieldDetector.class).withArguments(new File(lastStep.getSnapshots().get(0).getScreenshot().getFullImagePath()), (double) 1, FieldType.ERROR_MESSAGES_AND_FIELDS).thenReturn(imageFieldDetector);
    List<Label> labels = new ArrayList<>();
    labels.add(new Label(0, 100, 20, 50, "il y a eu un gros problème"));
    labels.add(new Label(0, 100, 100, 120, "some error"));
    List<Field> fields = new ArrayList<>();
    fields.add(new Field(0, 100, 0, 20, "", "field"));
    fields.add(new Field(0, 100, 200, 220, "", "field"));
    when(imageFieldDetector.detectFields()).thenReturn(fields);
    when(imageFieldDetector.detectLabels()).thenReturn(labels);
    List<ErrorCause> causes = new ErrorCauseFinder(testResult).findErrorInLastStepSnapshots();
    Assert.assertEquals(causes.size(), 2);
    Assert.assertEquals(causes.get(0).getType(), ErrorType.ERROR_MESSAGE);
    // no failed step except "last step", keep association
    Assert.assertEquals(causes.get(0).getTestStep(), lastStep);
    Assert.assertEquals(causes.get(0).getDescription(), "il y a eu un gros problème");
    Assert.assertEquals(causes.get(1).getType(), ErrorType.ERROR_MESSAGE);
    Assert.assertEquals(causes.get(1).getDescription(), "some error");
    Assert.assertEquals(causes.get(1).getTestStep(), lastStep);
    Assert.assertTrue(TestNGResultUtils.isErrorCauseSearchedInLastStep(testResult));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) ErrorCauseFinder(com.seleniumtests.core.testanalysis.ErrorCauseFinder) ITestResult(org.testng.ITestResult) ErrorCause(com.seleniumtests.core.testanalysis.ErrorCause) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) GenericTest(com.seleniumtests.GenericTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 35 with Field

use of com.seleniumtests.connectors.selenium.fielddetector.Field in project seleniumRobot by bhecquet.

the class TestUiElement method init.

@BeforeMethod(groups = { "ut" })
public void init() {
    UiElement.resetPageInformation();
    /*
		 * Create fields and labels
		 * 
		 * 								field4
		 * 
		 * 								label1Below
		 * 
		 *	field5		label1Right		field1/labelInside		label1Left		field3
		 * 
		 * 								label1Above
		 * 
		 * 								field2
		 * 
		 */
    // field to the left of "label1Left" and to the right of "label1Right"
    field1 = new Field(200, 300, 100, 120, null, "field");
    fieldWithLabel = new Field(100, 300, 100, 120, null, "field_with_label", field1);
    // field above "label1Above"
    field2 = new Field(200, 300, 300, 320, null, "field");
    // field to the right of "label1Left"
    field3 = new Field(600, 700, 100, 120, null, "field");
    // field above "label1Below"
    field4 = new Field(200, 300, 0, 20, null, "field");
    // field to the left of "label1Right"
    field5 = new Field(10, 60, 100, 120, null, "field");
    label1Right = new Label(100, 150, 100, 120, "label_with_field_on_right");
    label1Left = new Label(350, 400, 100, 120, "label_with_field_on_left");
    // label longer than field
    label1Above = new Label(200, 400, 200, 220, "label_with_field_above");
    // label shorter than field
    label1Below = new Label(200, 252, 70, 90, "label_with_field_below");
    label2 = new Label(100, 150, 0, 20, "label_without_field");
    labelInside = new Label(200, 250, 100, 120, "label_inside");
    PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
    PowerMockito.mockStatic(WebUIDriver.class);
    PowerMockito.when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(driver);
    when(driver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.CHROME, "83.0"));
}
Also used : Field(com.seleniumtests.connectors.selenium.fielddetector.Field) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) Label(com.seleniumtests.connectors.selenium.fielddetector.Label) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Field (com.seleniumtests.connectors.selenium.fielddetector.Field)35 Test (org.testng.annotations.Test)29 GenericTest (com.seleniumtests.GenericTest)23 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)22 File (java.io.File)17 MockitoTest (com.seleniumtests.MockitoTest)14 JSONObject (kong.unirest.json.JSONObject)14 ArrayList (java.util.ArrayList)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 ImageFieldDetector (com.seleniumtests.connectors.selenium.fielddetector.ImageFieldDetector)9 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)8 ErrorCauseFinder (com.seleniumtests.core.testanalysis.ErrorCauseFinder)8 ITestResult (org.testng.ITestResult)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)5 Rectangle (java.awt.Rectangle)4 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)2 Snapshot (com.seleniumtests.reporter.logger.Snapshot)2 TestStep (com.seleniumtests.reporter.logger.TestStep)2 StepReferenceComparator (com.seleniumtests.util.imaging.StepReferenceComparator)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1