Search in sources :

Example 51 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project vorto by eclipse.

the class BasicRepositoryUITest method testCreateInfoModel.

/**
 * Tests to create a model.
 */
@Test
public void testCreateInfoModel() {
    RemoteWebDriver remoteWebDriver = this.seleniumVortoHelper.getRemoteWebDriver();
    // there should be no create button before logging in.
    List<WebElement> createModelButtonList = this.seleniumVortoHelper.getRemoteWebDriver().findElementsByXPath("//a[@ng-click='openCreateModelDialog()']");
    Assert.assertTrue(createModelButtonList.isEmpty());
    // create a namespace (reuse existing test)
    testCreateNamespace();
    // now the create button should be available
    this.seleniumVortoHelper.gotoWelcomePage();
    remoteWebDriver.findElementByXPath("//a[@ng-click='openCreateModelDialog()']").click();
    remoteWebDriver.findElementByXPath("//input[@name='modelType' and @value='InformationModel']").click();
    remoteWebDriver.findElementByXPath("//button[contains(@ng-click,'next(')]").click();
    Select namespaceComboBox = new Select(remoteWebDriver.findElementById(SeleniumVortoHelper.ID_CB_NAMESPACE_ROOT));
    namespaceComboBox.selectByVisibleText(SeleniumVortoHelper.PRIVATE_NAMESPACE_PREFIX + SeleniumVortoHelper.USER1_PRIVATE_NAMESPACE);
    WebElement modelNameTextField = remoteWebDriver.findElementByName("modelName");
    modelNameTextField.sendKeys(SeleniumVortoHelper.USER1_EMPTY_INFO_MODEL);
    remoteWebDriver.findElementByXPath("//button[contains(@ng-click,'next(')]").click();
    remoteWebDriver.findElementByXPath("//button[text()='Create']").click();
    // wait for the model details dialog to show up.
    remoteWebDriver.findElementByXPath("//dd[@class='ng-binding' and .='" + SeleniumVortoHelper.USER1_EMPTY_INFO_MODEL + "']");
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 52 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project vorto by eclipse.

the class BasicRepositoryUITest method testTitle.

/**
 * Tests if the title is correct.
 */
@Test
public void testTitle() {
    final RemoteWebDriver webDriver = chrome.getWebDriver();
    webDriver.get(rootUrl);
    String title = webDriver.getTitle();
    Assert.assertEquals("Vorto Repository - Manages standardized IoT device descriptions", title);
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Test(org.junit.Test)

Example 53 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.

the class ReportContext method getUrl.

/**
 * generate url for artifact by name
 *
 * @param driver WebDriver
 * @param name String
 * @return String
 */
private static String getUrl(WebDriver driver, String name) {
    String seleniumHost = Configuration.getSeleniumUrl().replace("wd/hub", "download/");
    WebDriver drv = (driver instanceof EventFiringWebDriver) ? ((EventFiringWebDriver) driver).getWrappedDriver() : driver;
    String sessionId = ((RemoteWebDriver) drv).getSessionId().toString();
    String url = seleniumHost + sessionId + "/" + name;
    LOGGER.debug("url: " + url);
    return url;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver)

Example 54 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.

the class DriverHelper method getSelenoidClipboardUrl.

private String getSelenoidClipboardUrl(WebDriver driver) {
    String seleniumHost = Configuration.getSeleniumUrl().replace("wd/hub", "clipboard/");
    if (seleniumHost.isEmpty()) {
        seleniumHost = Configuration.getEnvArg(Parameter.URL.getKey()).replace("wd/hub", "clipboard/");
    }
    WebDriver drv = (driver instanceof EventFiringWebDriver) ? ((EventFiringWebDriver) driver).getWrappedDriver() : driver;
    String sessionId = ((RemoteWebDriver) drv).getSessionId().toString();
    String url = seleniumHost + sessionId;
    LOGGER.debug("url: " + url);
    return url;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver)

Example 55 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.

the class ExtendedWebElement method overrideAction.

// single place for all supported UI actions in carina core
private Object overrideAction(ACTION_NAME actionName, Object... inputArgs) {
    Object output = executeAction(actionName, new ActionSteps() {

        @Override
        public void doClick() {
            try {
                DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));
                try {
                    element.click();
                } catch (ElementNotInteractableException e) {
                    // TODO: investigate if more exceptions should be catched
                    // not visible so we can't interact using selenium or actions
                    LOGGER.warn("Trying to do click by JavascriptExecutor because element '" + getNameWithLocator() + "' is not visible...");
                    JavascriptExecutor executor = (JavascriptExecutor) getDriver();
                    executor.executeScript("arguments[0].click();", element);
                }
            } catch (WebDriverException e) {
                if (e != null && (e.getMessage().contains("Other element would receive the click:"))) {
                    LOGGER.warn("Trying to do click by Actions due to the: " + e.getMessage());
                    Actions actions = new Actions(getDriver());
                    actions.moveToElement(element).click().perform();
                } else {
                    throw e;
                }
            }
        }

        @Override
        public // click for mobile devices
        void doTap() {
            DriverListener.setMessages(Messager.ELEMENT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_CLICKED.getMessage(getNameWithLocator()));
            element.click();
        }

        @Override
        public void doDoubleClick() {
            DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator()));
            WebDriver drv = getDriver();
            Actions action = new Actions(drv);
            action.moveToElement(element).doubleClick(element).build().perform();
        }

        @Override
        public void doHover(Integer xOffset, Integer yOffset) {
            DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()), Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator()));
            WebDriver drv = getDriver();
            Actions action = new Actions(drv);
            if (xOffset != null && yOffset != null) {
                action.moveToElement(element, xOffset, yOffset).build().perform();
            } else {
                action.moveToElement(element).build().perform();
            }
        }

        @Override
        public void doSendKeys(Keys keys) {
            DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(keys.toString(), getName()), Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(keys.toString(), getNameWithLocator()));
            element.sendKeys(keys);
        }

        @Override
        public void doType(String text) {
            final String decryptedText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);
            /*				if (!element.getText().isEmpty()) {
    				DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()),
    						Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));
    				element.clear();
				}
*/
            DriverListener.setMessages(Messager.KEYS_CLEARED_IN_ELEMENT.getMessage(getName()), Messager.KEYS_NOT_CLEARED_IN_ELEMENT.getMessage(getNameWithLocator()));
            element.clear();
            String textLog = (!decryptedText.equals(text) ? "********" : text);
            DriverListener.setMessages(Messager.KEYS_SEND_TO_ELEMENT.getMessage(textLog, getName()), Messager.KEYS_NOT_SEND_TO_ELEMENT.getMessage(textLog, getNameWithLocator()));
            element.sendKeys(decryptedText);
        }

        @Override
        public void doAttachFile(String filePath) {
            final String decryptedText = cryptoTool.decryptByPattern(filePath, CRYPTO_PATTERN);
            String textLog = (!decryptedText.equals(filePath) ? "********" : filePath);
            DriverListener.setMessages(Messager.FILE_ATTACHED.getMessage(textLog, getName()), Messager.FILE_NOT_ATTACHED.getMessage(textLog, getNameWithLocator()));
            ((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", element);
            ((RemoteWebDriver) castDriver(getDriver())).setFileDetector(new LocalFileDetector());
            element.sendKeys(decryptedText);
        }

        @Override
        public String doGetText() {
            String text = element.getText();
            LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Text", text, getName()));
            return text;
        }

        @Override
        public Point doGetLocation() {
            Point point = element.getLocation();
            LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Location", point.toString(), getName()));
            return point;
        }

        @Override
        public Dimension doGetSize() {
            Dimension dim = element.getSize();
            LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage("Size", dim.toString(), getName()));
            return dim;
        }

        @Override
        public String doGetAttribute(String name) {
            String attribute = element.getAttribute(name);
            LOGGER.debug(Messager.ELEMENT_ATTRIBUTE_FOUND.getMessage(name, attribute, getName()));
            return attribute;
        }

        @Override
        public void doRightClick() {
            DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator()));
            WebDriver drv = getDriver();
            Actions action = new Actions(drv);
            action.moveToElement(element).contextClick(element).build().perform();
        }

        @Override
        public void doCheck() {
            DriverListener.setMessages(Messager.CHECKBOX_CHECKED.getMessage(getName()), null);
            boolean isSelected = element.isSelected();
            if (element.getAttribute("checked") != null) {
                isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");
            }
            if (!isSelected) {
                click();
            }
        }

        @Override
        public void doUncheck() {
            DriverListener.setMessages(Messager.CHECKBOX_UNCHECKED.getMessage(getName()), null);
            boolean isSelected = element.isSelected();
            if (element.getAttribute("checked") != null) {
                isSelected |= element.getAttribute("checked").equalsIgnoreCase("true");
            }
            if (isSelected) {
                click();
            }
        }

        @Override
        public boolean doIsChecked() {
            boolean res = element.isSelected();
            if (element.getAttribute("checked") != null) {
                res |= element.getAttribute("checked").equalsIgnoreCase("true");
            }
            return res;
        }

        @Override
        public boolean doSelect(String text) {
            final String decryptedSelectText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN);
            String textLog = (!decryptedSelectText.equals(text) ? "********" : text);
            DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(textLog, getName()), Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(textLog, getNameWithLocator()));
            final Select s = new Select(getCachedElement());
            // [VD] do not use selectByValue as modern controls could have only visible value without value
            s.selectByVisibleText(decryptedSelectText);
            return true;
        }

        @Override
        public boolean doSelectValues(String[] values) {
            boolean result = true;
            for (String value : values) {
                if (!select(value)) {
                    result = false;
                }
            }
            return result;
        }

        @Override
        public boolean doSelectByMatcher(BaseMatcher<String> matcher) {
            DriverListener.setMessages(Messager.SELECT_BY_MATCHER_TEXT_PERFORMED.getMessage(matcher.toString(), getName()), Messager.SELECT_BY_MATCHER_TEXT_NOT_PERFORMED.getMessage(matcher.toString(), getNameWithLocator()));
            final Select s = new Select(getCachedElement());
            String fullTextValue = null;
            for (WebElement option : s.getOptions()) {
                if (matcher.matches(option.getText())) {
                    fullTextValue = option.getText();
                    break;
                }
            }
            s.selectByVisibleText(fullTextValue);
            return true;
        }

        @Override
        public boolean doSelectByPartialText(String partialSelectText) {
            DriverListener.setMessages(Messager.SELECT_BY_TEXT_PERFORMED.getMessage(partialSelectText, getName()), Messager.SELECT_BY_TEXT_NOT_PERFORMED.getMessage(partialSelectText, getNameWithLocator()));
            final Select s = new Select(getCachedElement());
            String fullTextValue = null;
            for (WebElement option : s.getOptions()) {
                if (option.getText().contains(partialSelectText)) {
                    fullTextValue = option.getText();
                    break;
                }
            }
            s.selectByVisibleText(fullTextValue);
            return true;
        }

        @Override
        public boolean doSelectByIndex(int index) {
            DriverListener.setMessages(Messager.SELECT_BY_INDEX_PERFORMED.getMessage(String.valueOf(index), getName()), Messager.SELECT_BY_INDEX_NOT_PERFORMED.getMessage(String.valueOf(index), getNameWithLocator()));
            final Select s = new Select(getCachedElement());
            s.selectByIndex(index);
            return true;
        }

        @Override
        public String doGetSelectedValue() {
            final Select s = new Select(getCachedElement());
            return s.getAllSelectedOptions().get(0).getText();
        }

        @Override
        public List<String> doGetSelectedValues() {
            final Select s = new Select(getCachedElement());
            List<String> values = new ArrayList<String>();
            for (WebElement we : s.getAllSelectedOptions()) {
                values.add(we.getText());
            }
            return values;
        }
    }, inputArgs);
    return output;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Actions(org.openqa.selenium.interactions.Actions) LocalFileDetector(org.openqa.selenium.remote.LocalFileDetector) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) IWebElement(com.qaprosoft.carina.core.foundation.utils.IWebElement) Point(org.openqa.selenium.Point) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) Keys(org.openqa.selenium.Keys) Select(org.openqa.selenium.support.ui.Select) List(java.util.List) ArrayList(java.util.ArrayList) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)101 URL (java.net.URL)39 Test (org.junit.Test)36 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)29 File (java.io.File)16 WebDriver (org.openqa.selenium.WebDriver)14 MalformedURLException (java.net.MalformedURLException)13 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)13 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)12 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)12 IOException (java.io.IOException)11 Dimension (org.openqa.selenium.Dimension)9 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)6 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5