Search in sources :

Example 41 with HtmlElement

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

the class TestFrameElement method testUseElementInsideFrameWithIndex.

/**
 * issue #276: Check that we can switch to a frame by index
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testUseElementInsideFrameWithIndex() throws Exception {
    ArgumentCaptor<WebElement> frameArgument = ArgumentCaptor.forClass(WebElement.class);
    FrameElement frame = new FrameElement("", By.tagName("iframe"), 1);
    HtmlElement el = new HtmlElement("", By.id("el"), frame);
    el.click();
    verify(locator).frame(frameArgument.capture());
    Assert.assertEquals(frameArgument.getValue().getText(), "222");
    verify(locator).defaultContent();
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 42 with HtmlElement

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

the class TestFrameElement method testUseElementInsideFrame.

@Test(groups = { "ut" })
public void testUseElementInsideFrame() throws Exception {
    ArgumentCaptor<WebElement> frameArgument = ArgumentCaptor.forClass(WebElement.class);
    FrameElement frame = new FrameElement("", By.id("frameId"));
    HtmlElement el = new HtmlElement("", By.id("el"), frame);
    el.click();
    verify(locator).frame(frameArgument.capture());
    Assert.assertEquals(frameArgument.getValue().getText(), "111");
    verify(locator).defaultContent();
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 43 with HtmlElement

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

the class TestFrameElement method testUseElementInsideFrameWithWrongIndex.

/**
 * issue #276: Check a clear error is raised when an invalid index is given for finding a frame
 * @throws Exception
 */
@Test(groups = { "ut" }, expectedExceptions = NoSuchFrameException.class)
public void testUseElementInsideFrameWithWrongIndex() throws Exception {
    FrameElement frame = new FrameElement("", By.tagName("iframe"), 2);
    HtmlElement el = new HtmlElement("", By.id("el"), frame);
    el.click();
}
Also used : HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 44 with HtmlElement

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

the class TestHtmlElement method testFindSubElement.

/**
 * Check we get the first sub-element of our root element "el"
 */
@Test(groups = { "ut" })
public void testFindSubElement() throws Exception {
    HtmlElement subEl = el.findElement(By.name("subEl"));
    Assert.assertEquals(subEl.getElement().toString(), "subElement1");
    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 45 with HtmlElement

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

the class TestHtmlElement method testIsElementPresentFoundWithFrame.

/**
 * Check that element is found with frame
 * @throws Exception
 */
@Test(groups = { "ut" })
public void testIsElementPresentFoundWithFrame() throws Exception {
    HtmlElement present = new HtmlElement("element", By.id("present"), frame);
    when(driver.findElement(By.id("present"))).thenReturn(el);
    LocalDateTime start = LocalDateTime.now();
    boolean exceptionRaised = false;
    try {
        present.waitForPresent(5);
    } catch (TimeoutException e) {
        exceptionRaised = true;
    }
    verify(driver.switchTo()).frame(any(WebElement.class));
    Assert.assertFalse(exceptionRaised);
    Assert.assertTrue(LocalDateTime.now().minusSeconds(5).isBefore(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)

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