Example usage for org.openqa.selenium By toString

List of usage examples for org.openqa.selenium By toString

Introduction

In this page you can find the example usage for org.openqa.selenium By toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.consol.citrus.selenium.actions.FindElementActionTest.java

License:Apache License

@Test
public void testExecuteFindByVariableSupport() throws Exception {
    when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {
        @Override//from  w  w  w  . j  a  v a2 s.com
        public WebElement answer(InvocationOnMock invocation) throws Throwable {
            By select = (By) invocation.getArguments()[0];

            Assert.assertEquals(select.getClass(), By.ById.class);
            Assert.assertEquals(select.toString(), By.id("clickMe").toString());
            return element;
        }
    });

    context.setVariable("myId", "clickMe");

    action.setProperty("id");
    action.setPropertyValue("${myId}");

    action.execute(context);

    Assert.assertEquals(context.getVariableObject("button"), element);
}

From source file:com.consol.citrus.selenium.actions.FindElementActionTest.java

License:Apache License

@Test
public void testExecuteFindByValidation() throws Exception {
    when(element.getText()).thenReturn("Click Me!");
    when(element.getAttribute("type")).thenReturn("submit");
    when(element.getCssValue("color")).thenReturn("red");

    when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {
        @Override/*  w  w w  .  ja v  a2 s. co m*/
        public WebElement answer(InvocationOnMock invocation) throws Throwable {
            By select = (By) invocation.getArguments()[0];

            Assert.assertEquals(select.getClass(), By.ByName.class);
            Assert.assertEquals(select.toString(), By.name("clickMe").toString());
            return element;
        }
    });

    action.setTagName("button");
    action.setText("Click Me!");
    action.setAttributes(Collections.singletonMap("type", "submit"));
    action.setStyles(Collections.singletonMap("color", "red"));

    action.setProperty("name");
    action.setPropertyValue("clickMe");

    action.execute(context);

    Assert.assertEquals(context.getVariableObject("button"), element);
}

From source file:com.consol.citrus.selenium.actions.FindElementActionTest.java

License:Apache License

@Test(dataProvider = "validationErrorProvider")
public void testExecuteFindByValidationFailed(String tagName, String text, String attribute, String cssStyle,
        boolean displayed, boolean enabled, String errorMsg) throws Exception {
    when(element.getTagName()).thenReturn("button");
    when(element.getText()).thenReturn("Click Me!");
    when(element.getAttribute("type")).thenReturn("submit");
    when(element.getCssValue("color")).thenReturn("red");

    when(webDriver.findElement(any(By.class))).thenAnswer(new Answer<WebElement>() {
        @Override//from ww w .ja va2  s .  c o  m
        public WebElement answer(InvocationOnMock invocation) throws Throwable {
            By select = (By) invocation.getArguments()[0];

            Assert.assertEquals(select.getClass(), By.ByName.class);
            Assert.assertEquals(select.toString(), By.name("clickMe").toString());
            return element;
        }
    });

    action.setTagName(tagName);
    action.setText(text);
    action.setAttributes(Collections.singletonMap("type", attribute));
    action.setStyles(Collections.singletonMap("color", cssStyle));
    action.setDisplayed(displayed);
    action.setEnabled(enabled);

    action.setProperty("name");
    action.setPropertyValue("clickMe");

    try {
        action.execute(context);
        Assert.fail("Missing exception to to validation error");
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().endsWith(errorMsg), e.getMessage());
    }
}

From source file:com.constellio.sdk.tests.selenium.adapters.base.RequiredElementNotFound.java

License:Open Source License

public RequiredElementNotFound(By by) {
    super("Impossible de trouver un lment correspondant  " + by.toString());
}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java

License:Open Source License

private WebElement nestedFindElement(By by) {
    try {/*from  w  w w .jav  a2 s.c  o m*/
        return adapted.findElement(by);
    } catch (Throwable t) {
        String errorMessage = "Cannot find element " + by.toString().replace("By.", "by ");
        throw new RuntimeException(errorMessage, t);
    }

}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java

License:Open Source License

@Override
public WE findElement(final By by) {
    ensureNoApplicationException();/*from   w  w w. jav a 2s.  co m*/
    WebElement element = nestedFindElement(by);

    if (element == null) {
        return null;
    } else {
        WebElementFinder<WebElement> factory = new WebElementFinder<WebElement>() {

            @Override
            public WebElement get() {
                ensureNoApplicationException();
                return WebDriverAdapter.this.getAdaptedDriver().findElement(by);
            }

            @Override
            public String getOperationDescription() {
                return "webDriver.find(" + by.toString() + ")";
            }
        };
        factory.getUsingCache();
        return adapt(factory);
    }
}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java

License:Open Source License

public WE findElementAtIndex(final By by, final int index) {
    WebElementFinder<WebElement> factory = new WebElementFinder<WebElement>() {

        @Override//w w w .j  a va2s  .  c  om
        public WebElement get() {
            ensureNoApplicationException();
            return WebDriverAdapter.this.getAdaptedDriver().findElements(by).get(index);
        }

        @Override
        public String getOperationDescription() {
            return "webDriver.findElements(" + by.toString() + ")";
        }
    };
    factory.getUsingCache();
    return adapt(factory);
}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebElementAdapter.java

License:Open Source License

public WebElementAdapter(WD driver, final By by) {
    super();//from   w ww  . jav a  2 s  .c  om
    this.webDriver = driver;
    this.adaptedElementFinder = new WebElementFinder<WebElement>() {

        @Override
        public WebElement get() {
            webDriver.ensureNoApplicationException();
            return WebElementAdapter.this.webDriver.findElement(by);
        }

        @Override
        public String getOperationDescription() {
            return "webDriver.find(" + by.toString() + ")";
        }

    };
    this.adaptedElementFinder.getUsingCache();

}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebElementAdapter.java

License:Open Source License

public WebElementAdapter(final WebElementAdapter<?, WD> webElement, final By by) {
    super();/*from w  ww.  java  2  s  .com*/
    this.webDriver = webElement.webDriver;
    this.adaptedElementFinder = new WebElementFinder<WebElement>() {

        @Override
        public WebElement get() {
            webDriver.ensureNoApplicationException();
            return webElement.findElement(by);
        }

        @Override
        public String getOperationDescription() {
            return webElement.toString() + ".find(" + by.toString() + ")";
        }
    };
    this.adaptedElementFinder.getUsingCache();
}

From source file:com.constellio.sdk.tests.selenium.adapters.base.WebElementAdapter.java

License:Open Source License

@Override
public WE findElement(final By by) {
    WebElementFinder<WebElement> factory = new WebElementFinder<WebElement>() {

        @Override//ww w  .  j  av  a 2 s .co  m
        public WebElement get() {
            webDriver.ensureNoApplicationException();
            return getAdaptedElement().findElement(by);
        }

        @Override
        public String getOperationDescription() {
            return getAdaptedElement().toString() + ".find(" + by.toString() + ")";
        }
    };
    factory.getUsingCache();
    return adapt(factory, webDriver);
}