base.GalenTestBase.java Source code

Java tutorial

Introduction

Here is the source code for base.GalenTestBase.java

Source

package base;

import com.galenframework.testng.GalenTestNgTestBase;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.DataProvider;

import java.util.List;

import static java.util.Arrays.asList;

public abstract class GalenTestBase extends GalenTestNgTestBase {

    private static final String ENV_URL = "http://wpl-licensee43-admin.ptdev.eu"; //http://testapp.galenframework.com";

    @Override
    public WebDriver createDriver(Object[] args) {
        WebDriver driver = new FirefoxDriver();
        if (args.length > 0) {
            if (args[0] != null && args[0] instanceof TestDevice) {
                TestDevice device = (TestDevice) args[0];
                if (device.getScreenSize() != null) {
                    driver.manage().window().setSize(device.getScreenSize());
                }
            }
        }
        return driver;
    }

    public void load(String uri) {
        getDriver().get(ENV_URL + uri);
    }

    @DataProvider(name = "devices")
    public Object[][] devices() {
        return new Object[][] { { new TestDevice("mobile", new Dimension(450, 800), asList("mobile")) },
                { new TestDevice("tablet", new Dimension(750, 800), asList("tablet")) },
                { new TestDevice("desktop", new Dimension(1024, 800), asList("desktop")) },
                { new TestDevice("iPhone 5s", new Dimension(640, 1136), asList("mobile")) } };
    }

    public static class TestDevice {
        private final String name;
        private final Dimension screenSize;
        private final List<String> tags;

        public TestDevice(String name, Dimension screenSize, List<String> tags) {
            this.name = name;
            this.screenSize = screenSize;
            this.tags = tags;
        }

        public String getName() {
            return name;
        }

        public Dimension getScreenSize() {
            return screenSize;
        }

        public List<String> getTags() {
            return tags;
        }
    }
}