コード例 #1
0
        public MobileDriver(IAutomationConfiguration configuration, BrowserDriverEnumeration browserVendor = BrowserDriverEnumeration.Android) : base(configuration, browserVendor)
        {
            BrowserVendor = browserVendor;

            var ops = new AppiumOptions();

            ops.AddAdditionalCapability(MobileCapabilityType.DeviceName, Config.GetConfigSetting("AppiumDeviceName", ""));
            ops.AddAdditionalCapability(MobileCapabilityType.PlatformName, Config.GetConfigSetting("AppiumPlatformName", ""));
            ops.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, Config.GetConfigSetting("AppiumPlatformVersion", ""));
            ops.AddAdditionalCapability(MobileCapabilityType.App, Config.GetConfigSetting("AppiumApp", ""));
            ops.AddAdditionalCapability(MobileCapabilityType.BrowserName, Config.GetConfigSetting("AppiumBrowserName", ""));
            ops.AddAdditionalCapability(MobileCapabilityType.NewCommandTimeout, "120");//unsure if this is enough/too much
            ops.AddAdditionalCapability(MobileCapabilityType.Orientation, Config.GetConfigSetting("AppiumOrientation", "PORTRAIT"));

            var uri = Config.GetConfigSetting("AppiumServerUri", "http://127.0.01:4723/wd/hub");

            switch (BrowserVendor)
            {
            case BrowserDriverEnumeration.Windows:
                RawWebDriver = new WindowsDriver <IWebElement>(new Uri(uri), ops);
                break;

            case BrowserDriverEnumeration.Android:
                RawWebDriver = new AndroidDriver <IWebElement>(new Uri(uri), ops);
                break;

            case BrowserDriverEnumeration.IOS:
                RawWebDriver = new IOSDriver <IWebElement>(new Uri(uri), ops);
                break;
            }
        }
コード例 #2
0
        public BrowserDriver(IAutomationConfiguration configuration, BrowserDriverEnumeration browserVendor = BrowserDriverEnumeration.Firefox)
        {
            //add default screen size
            //add ability for custom settings in config
            //Add 'uri' for remote execution
            var uri = Config.GetConfigSetting("SeleniumHubUrl");

            switch (browserVendor)
            {
            case BrowserDriverEnumeration.Chrome:
                var chromeOps = new ChromeOptions();
                chromeOps.AddArgument("--start-maximized");
                chromeOps.AddArgument("--disable-extensions");
                Browser    = new ChromeDriver("./", chromeOps);
                DriverType = "Chrome";
                break;

            case BrowserDriverEnumeration.ChromeRemote:
                var chromeROps = new ChromeOptions();
                chromeROps.AddArgument("--start-maximized");
                chromeROps.AddArgument("--disable-extensions");
                Browser    = new RemoteWebDriver(new Uri(uri), chromeROps);
                DriverType = "Chrome";
                CodePagesEncodingProvider.Instance.GetEncoding(437);
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                ((RemoteWebDriver)Browser).FileDetector = new LocalFileDetector();
                break;

            case BrowserDriverEnumeration.Firefox:
                var ffOps = new FirefoxOptions();
                ffOps.AddArgument("--start-maximized");
                ffOps.AddArgument("--disable-extensions");
                Browser    = new FirefoxDriver("./", ffOps);
                DriverType = "FireFox";
                break;

            case BrowserDriverEnumeration.FirefoxRemote:
                var ffROps = new FirefoxOptions();
                ffROps.AddArgument("--start-maximized");
                ffROps.AddArgument("--disable-extensions");
                Browser    = new RemoteWebDriver(new Uri(uri), ffROps);
                DriverType = "FireFox";
                CodePagesEncodingProvider.Instance.GetEncoding(437);
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                ((RemoteWebDriver)Browser).FileDetector = new LocalFileDetector();
                break;

            case BrowserDriverEnumeration.IE:
                var ieOps = new InternetExplorerOptions();
                //ieOps.AddAdditionalCapability("--start-maximized");
                //ieOps.AddAdditionalCapability("--disable-extensions");
                Browser    = new InternetExplorerDriver(ieOps);
                DriverType = "IE";
                break;

            case BrowserDriverEnumeration.IERemote:
                var ieROps = new InternetExplorerOptions();
                //ieROps.AddAdditionalCapability("--start-maximized");
                //ieROps.AddAdditionalCapability("--disable-extensions");
                Browser    = new RemoteWebDriver(new Uri(uri), ieROps);
                DriverType = "IE";
                break;

            case BrowserDriverEnumeration.Edge:
                var edgeOps = new EdgeOptions();
                //edgeOps.AddAdditionalCapability("--start-maximized");
                //edgeOps.AddAdditionalCapability("--disable-extensions");
                Browser    = new EdgeDriver(edgeOps);
                DriverType = "Edge";
                break;

            case BrowserDriverEnumeration.EdgeRemote:
                var edgeROps = new EdgeOptions();
                //edgeROps.AddAdditionalCapability("--start-maximized");
                //edgeROps.AddAdditionalCapability("--disable-extensions");
                Browser    = new RemoteWebDriver(new Uri(uri), edgeROps);
                DriverType = "Edge";
                break;

            case BrowserDriverEnumeration.SauceLabs:
                var capabilities = GetDesiredCapabilities(configuration);
                var url          = new Uri("http://" + configuration.SauceLabsKey + "@ondemand.saucelabs.com:80/wd/hub");
                Browser = new RemoteWebDriver(url, capabilities);
                CodePagesEncodingProvider.Instance.GetEncoding(437);
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                ((RemoteWebDriver)Browser).FileDetector = new LocalFileDetector();
                break;
            }
        }