Search in sources :

Example 16 with FrameElement

use of com.seleniumtests.uipage.htmlelements.FrameElement 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 17 with FrameElement

use of com.seleniumtests.uipage.htmlelements.FrameElement 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 18 with FrameElement

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

the class TestHtmlElement method init.

@BeforeMethod(groups = { "ut" })
private void init() throws WebDriverException, IOException {
    // mimic sub elements of the HtmlElement
    List<WebElement> subElList = new ArrayList<WebElement>();
    subElList.add(subElement1);
    subElList.add(subElement2);
    // list of elements correspond
    List<WebElement> elList = new ArrayList<WebElement>();
    elList.add(element);
    // add DriverExceptionListener to reproduce driver behavior
    eventDriver = spy(new CustomEventFiringWebDriver(driver).register(new DriverExceptionListener()));
    PowerMockito.mockStatic(WebUIDriver.class);
    when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
    when(WebUIDriver.getWebUIDriver(anyBoolean())).thenReturn(uiDriver);
    when(driver.findElement(By.id("el"))).thenReturn(element);
    when(driver.findElement(By.id("frame"))).thenReturn(frameElement);
    when(driver.findElements(By.id("frame"))).thenReturn(Arrays.asList(frameElement));
    when(driver.findElements(By.name("subEl"))).thenReturn(subElList);
    when(driver.findElement(By.name("subEl"))).thenReturn(subElement1);
    when(driver.findElements(By.id("el"))).thenReturn(elList);
    when(driver.getKeyboard()).thenReturn(keyboard);
    when(driver.getMouse()).thenReturn(mouse);
    when(driver.switchTo()).thenReturn(locator);
    when(driver.manage()).thenReturn(options);
    when(options.timeouts()).thenReturn(timeouts);
    when(driver.executeScript(anyString())).thenReturn(Arrays.asList(100, 100));
    when(uiDriver.getConfig()).thenReturn(driverConfig);
    when(driverConfig.getBrowserType()).thenReturn(BrowserType.HTMLUNIT);
    when(driverConfig.getMajorBrowserVersion()).thenReturn(1);
    when(element.findElement(By.name("subEl"))).thenReturn(subElement1);
    when(element.findElements(By.name("subEl"))).thenReturn(subElList);
    when(element.getAttribute(anyString())).thenReturn("attribute");
    when(element.getSize()).thenReturn(new Dimension(10, 10));
    when(element.getLocation()).thenReturn(new Point(5, 5));
    when(frame.getLocation()).thenReturn(new Point(5, 5));
    when(element.getTagName()).thenReturn("h1");
    when(element.getText()).thenReturn("text");
    when(element.isDisplayed()).thenReturn(true);
    when(element.isEnabled()).thenReturn(true);
    when(subElement1.isDisplayed()).thenReturn(true);
    when(subElement2.isDisplayed()).thenReturn(true);
    when(subElement1.getLocation()).thenReturn(new Point(5, 5));
    when(subElement2.getLocation()).thenReturn(new Point(5, 5));
    when(mobileElement.getCenter()).thenReturn(new Point(2, 2));
    when(mobileElement.getLocation()).thenReturn(new Point(1, 1));
    when(mobileElement.isDisplayed()).thenReturn(true);
    when(mobileElement.getId()).thenReturn("12");
    // init for mobile tests
    AppiumCommandExecutor ce = Mockito.mock(AppiumCommandExecutor.class);
    Response response = new Response(new SessionId("1"));
    response.setValue(new HashMap<String, Object>());
    Response findResponse = new Response(new SessionId("1"));
    findResponse.setValue(mobileElement);
    when(ce.execute(any())).thenReturn(response, response, response, findResponse);
    doReturn(response).when(ce).execute(argThat(command -> DriverCommand.NEW_SESSION.equals(command.getName())));
    doReturn(response).when(ce).execute(argThat(command -> DriverCommand.FIND_ELEMENT.equals(command.getName())));
    doReturn(response).when(ce).execute(argThat(command -> "getSession".equals(command.getName())));
    // newSession, getSession, getSession, findElement
    mobileDriver = Mockito.spy(new AppiumDriver<>(ce, new DesiredCapabilities()));
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
    SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
}
Also used : StepStatus(com.seleniumtests.reporter.logger.TestStep.StepStatus) Arrays(java.util.Arrays) TargetLocator(org.openqa.selenium.WebDriver.TargetLocator) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Keyboard(org.openqa.selenium.interactions.Keyboard) Point(org.openqa.selenium.Point) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) TestType(com.seleniumtests.driver.TestType) Timeouts(org.openqa.selenium.WebDriver.Timeouts) Spy(org.mockito.Spy) Mockito.atLeast(org.mockito.Mockito.atLeast) TestStepManager(com.seleniumtests.core.TestStepManager) ScenarioException(com.seleniumtests.customexception.ScenarioException) Mockito.doReturn(org.mockito.Mockito.doReturn) AppiumCommandExecutor(io.appium.java_client.remote.AppiumCommandExecutor) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.doNothing(org.mockito.Mockito.doNothing) Mouse(org.openqa.selenium.interactions.Mouse) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) BrowserType(com.seleniumtests.driver.BrowserType) MockitoTest(com.seleniumtests.MockitoTest) List(java.util.List) TimeoutException(org.openqa.selenium.TimeoutException) TestStep(com.seleniumtests.reporter.logger.TestStep) Pattern(java.util.regex.Pattern) AppiumDriver(io.appium.java_client.AppiumDriver) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MobileElement(io.appium.java_client.MobileElement) Mock(org.mockito.Mock) TemporalUnit(java.time.temporal.TemporalUnit) WebDriverException(org.openqa.selenium.WebDriverException) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Assert(org.testng.Assert) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) WebUIDriver(com.seleniumtests.driver.WebUIDriver) Options(org.openqa.selenium.WebDriver.Options) PowerMockito(org.powermock.api.mockito.PowerMockito) DriverCommand(org.openqa.selenium.remote.DriverCommand) Dimension(org.openqa.selenium.Dimension) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Response(org.openqa.selenium.remote.Response) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) By(org.openqa.selenium.By) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Mockito.verify(org.mockito.Mockito.verify) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) ChronoUnit(java.time.temporal.ChronoUnit) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) SessionId(org.openqa.selenium.remote.SessionId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DriverConfig(com.seleniumtests.driver.DriverConfig) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) AppiumDriver(io.appium.java_client.AppiumDriver) AppiumCommandExecutor(io.appium.java_client.remote.AppiumCommandExecutor) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) Response(org.openqa.selenium.remote.Response) SessionId(org.openqa.selenium.remote.SessionId) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with FrameElement

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

the class TestFrameElement method testLabelElementInsideFrame.

@Test(groups = { "ut" })
public void testLabelElementInsideFrame() throws Exception {
    FrameElement frame = new FrameElement("", By.id("frameId"));
    LabelElement el = new LabelElement("", By.id("el"), frame);
    el.click();
    verify(locator).frame(any(WebElement.class));
    verify(locator).defaultContent();
}
Also used : LabelElement(com.seleniumtests.uipage.htmlelements.LabelElement) 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)

Aggregations

FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)19 MockitoTest (com.seleniumtests.MockitoTest)16 WebElement (org.openqa.selenium.WebElement)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Test (org.testng.annotations.Test)16 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)15 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)8 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)2 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)2 Around (org.aspectj.lang.annotation.Around)2 By (org.openqa.selenium.By)2 WebDriverException (org.openqa.selenium.WebDriverException)2 SeleniumTestsContextManager (com.seleniumtests.core.SeleniumTestsContextManager)1 TestStepManager (com.seleniumtests.core.TestStepManager)1 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 BrowserType (com.seleniumtests.driver.BrowserType)1 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)1 DriverConfig (com.seleniumtests.driver.DriverConfig)1 DriverExceptionListener (com.seleniumtests.driver.DriverExceptionListener)1 TestType (com.seleniumtests.driver.TestType)1