All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clarolab.selenium.pages.browser.mobile.IOSMobileBrowser Maven / Gradle / Ivy

Go to download

Framework for automated testing using Selenium. Provides easy configuration of WebDrivers with BrowserFactory. Provides a Page abstraction.

The newest version!
package com.clarolab.selenium.pages.browser.mobile;

import com.clarolab.selenium.pages.actions.IOSSeleniumActions;
import com.clarolab.selenium.pages.config.TimeoutsConfig;
import com.clarolab.selenium.pages.exception.FrameworkWebDriverException;
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.io.IOException;
import java.net.URL;
import java.util.HashMap;


/**
 * Added by Shiran.Dadon
 * Known bug of Apple from Xcode 5 and iOS 7.1 Simulator - swipe is not working on simulator.
 * As a workaround, using scrollTo in JavaScript.
 * As in real devices regular swipe works but not scrollTo, using the regular command as well
 */

public class IOSMobileBrowser extends MobileBrowser {

    public IOSMobileBrowser(String baseTestUrl,
                            String browserName,
                            String platform,
                            String platformName,
                            String platformVersion,
                            String deviceName,
                            String newCommandTimeout,
                            String automationName,
                            String version,
                            String autoLaunch,
                            String app,
                            boolean fullReset,
                            TimeoutsConfig timeouts) throws FrameworkWebDriverException {
        super(baseTestUrl, timeouts, browserName, platform, platformName, platformVersion, deviceName,
                newCommandTimeout, automationName, version, autoLaunch, app, fullReset);
    }

    @Override
    public DesiredCapabilities getDesiredCapabilities() {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, browserName);
        desiredCapabilities.setCapability("platform", platform);
        desiredCapabilities.setCapability("platformName", platformName);
        desiredCapabilities.setCapability("platformVersion", platformVersion);
        desiredCapabilities.setCapability("deviceName", deviceName);
        desiredCapabilities.setCapability("newCommandTimeout", newCommandTimeout);
        desiredCapabilities.setCapability("automationName", automationName);
        desiredCapabilities.setCapability("version", version);
        desiredCapabilities.setCapability("autoLaunch", autoLaunch);
        desiredCapabilities.setCapability("app", app);
        desiredCapabilities.setCapability("fullReset", fullReset);
        desiredCapabilities.setCapability("rotatable", "true");
        return desiredCapabilities;
    }

    protected IOSDriver createWebDriver() throws FrameworkWebDriverException {
        try {
            printCapabilities(getDesiredCapabilities());
            return new IOSDriver(new URL(getBaseTestUrl()), getDesiredCapabilities());
        } catch (IOException e) {
            throw new FrameworkWebDriverException("Error starting appium driver service", e);
        }
    }

    @Override
    public IOSSeleniumActions getActions() {
        return new IOSSeleniumActions(this);
    }
    /**
     * Swipe from the right to left for a second
     */
    public void swipeLeft() {
        super.swipeLeft();
        HashMap scrollObject = new HashMap();
        scrollObject.put("direction", "left");
        webDriver.executeScript("mobile: scroll", scrollObject);
    }

    /**
     * Swipe from the left to right for a second
     */
    public void swipeRight() {
        super.swipeRight();
        HashMap scrollObject = new HashMap();
        scrollObject.put("direction", "right");
        webDriver.executeScript("mobile: scroll", scrollObject);
    }

    /**
     * Swipe from the top to buttom for a second
     */
    public void dragDown() {
        int midScreen = getScreenWidth() / 2;
        TouchActions action = new TouchActions(webDriver);
        action.down(midScreen, 360).move(midScreen, 300).up(midScreen, 300).perform();

    }

    /**
     * Swipe from the down to up for a second
     */
    public void dragUp() {
        int midScreen = getScreenWidth() / 2;
        TouchActions action = new TouchActions(webDriver);
        action.down(midScreen, 300).move(midScreen, 250).up(midScreen, 250).perform();
    }

    /**
     *  Uses iOS functionality of automatic scroll to top when clicking status bar
     */
    public void scrollToTop() {
        getWebDriver().findElementByClassName("UIAStatusBar").click();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy