Search in sources :

Example 11 with HtmlElement

use of com.seleniumtests.uipage.htmlelements.HtmlElement in project seleniumRobot by bhecquet.

the class TestHtmlElement method testFindNthSubElement.

/**
 * Check we get the Nth sub-element of our root element "el"
 */
@Test(groups = { "ut" })
public void testFindNthSubElement() throws Exception {
    HtmlElement subEl = el.findElement(By.name("subEl"), 1);
    Assert.assertEquals(subEl.getElement().toString(), "subElement2");
    finalCheck(true);
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with HtmlElement

use of com.seleniumtests.uipage.htmlelements.HtmlElement in project seleniumRobot by bhecquet.

the class TestHtmlElement method testIsElementPresentNotFoundWithFrame.

/**
 * Check that element is not found if frame is not found
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testIsElementPresentNotFoundWithFrame() throws Exception {
    HtmlElement present = new HtmlElement("element", By.id("present"), frame);
    when(driver.findElement(By.id("present"))).thenReturn(el);
    when(driver.findElement(By.id("frame"))).thenThrow(NoSuchElementException.class);
    when(driver.findElements(By.id("frame"))).thenReturn(new ArrayList<>());
    LocalDateTime start = LocalDateTime.now();
    boolean exceptionRaised = false;
    try {
        present.waitForPresent(1);
    } catch (TimeoutException e) {
        exceptionRaised = true;
    }
    verify(driver.switchTo(), never()).frame(any(WebElement.class));
    Assert.assertTrue(exceptionRaised);
    Assert.assertTrue(LocalDateTime.now().minus(900, ChronoUnit.MILLIS).isAfter(start));
}
Also used : LocalDateTime(java.time.LocalDateTime) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with HtmlElement

use of com.seleniumtests.uipage.htmlelements.HtmlElement in project seleniumRobot by bhecquet.

the class TestPageObject2 method testCaptureElementSnapshotWithCheckAndDelay.

@Test(groups = { "ut" })
public void testCaptureElementSnapshotWithCheckAndDelay() throws IOException {
    SeleniumTestsContextManager.getThreadContext().setSnapshotScrollDelay(100);
    page.setScreenshotUtil(screenshotUtil);
    page.captureElementSnapshot("img", new HtmlElement("", By.id("el")), SnapshotCheckType.TRUE);
    // check scroll delay is applied
    verify(screenshotUtil).capture(any(SnapshotTarget.class), eq(ScreenShot.class), eq(100));
}
Also used : SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with HtmlElement

use of com.seleniumtests.uipage.htmlelements.HtmlElement in project seleniumRobot by bhecquet.

the class TestPageObject2 method testCaptureElementSnapshotWithoutCheckAndDelay.

/**
 * scrollDelay s set, but snapshot is not performed for control
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testCaptureElementSnapshotWithoutCheckAndDelay() throws IOException {
    SeleniumTestsContextManager.getThreadContext().setSnapshotScrollDelay(100);
    page.setScreenshotUtil(screenshotUtil);
    page.captureElementSnapshot("img", new HtmlElement("", By.id("el")), SnapshotCheckType.FALSE);
    // check scroll delay is 0 by default
    verify(screenshotUtil).capture(any(SnapshotTarget.class), eq(ScreenShot.class), eq(0));
}
Also used : SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with HtmlElement

use of com.seleniumtests.uipage.htmlelements.HtmlElement in project seleniumRobot by bhecquet.

the class TestPageObject2 method testCaptureElementSnapshotWithCheckNoName.

/**
 * Capture element snapshot and sends it to selenium server. No name is provided
 * ScenarioException should be raised
 *
 * @throws IOException
 */
@Test(groups = { "ut" }, expectedExceptions = ScenarioException.class)
public void testCaptureElementSnapshotWithCheckNoName() throws IOException {
    page.setScreenshotUtil(screenshotUtil);
    page.captureElementSnapshot("", new HtmlElement("", By.id("el")), SnapshotCheckType.TRUE);
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)50 WebElement (org.openqa.selenium.WebElement)24 Test (org.testng.annotations.Test)23 MockitoTest (com.seleniumtests.MockitoTest)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)12 ScenarioException (com.seleniumtests.customexception.ScenarioException)10 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)10 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)9 Element (com.seleniumtests.uipage.htmlelements.Element)9 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)9 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)9 TimeoutException (org.openqa.selenium.TimeoutException)9 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)8 LocalDateTime (java.time.LocalDateTime)8 NoSuchElementException (org.openqa.selenium.NoSuchElementException)8 Date (java.util.Date)5 WebDriverException (org.openqa.selenium.WebDriverException)5 Field (java.lang.reflect.Field)4 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)3