Esempio n. 1
0
        public void PassingAdditionalOptionsToOverrideRunSettingsServerParamsPasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName    = "chrome",
                RS_ServerHost     = "someHost",
                RS_ServerPort     = "1234",
                RS_ServerResource = "/abd/def"
            };

            DriverCapabilities  cap     = new DriverCapabilities(context);
            RunParameterUpdater options = new RunParameterUpdater();

            options
            .Update(nameof(Constants.RS_ServerHost), Constants.RS_ServerHost)
            .Update(nameof(Constants.RS_ServerPort), Constants.RS_ServerPort)
            .Update(nameof(Constants.RS_ServerResource), Constants.RS_ServerResource);
            cap.OverrideRunSettingsParams(options);

            Assert.AreEqual(context.RS_ServerHost, Constants.RS_ServerHost, $"{nameof(Constants.RS_ServerHost)} should have been updated.");
            Assert.AreEqual(context.RS_ServerPort, Constants.RS_ServerPort, $"{nameof(Constants.RS_ServerPort)} should have been updated.");
            Assert.AreEqual(context.RS_ServerResource, Constants.RS_ServerResource, $"{nameof(Constants.RS_ServerResource)} should have been updated.");
            context.ServerUri = Helpers.CreateUri(context.RS_ServerHost, context.RS_ServerPort, context.RS_ServerResource);
            Assert.AreEqual(context.ServerUri.Host, Constants.RS_ServerHost, $"{nameof(context.ServerUri.Host)} should have been updated.");
            Assert.AreEqual(context.ServerUri.Port, Convert.ToInt32(Constants.RS_ServerPort), $"{nameof(context.ServerUri.Port)} should have been updated.");
            Assert.AreEqual(context.ServerUri.PathAndQuery, Constants.RS_ServerResource, $"{nameof(context.ServerUri.PathAndQuery)} should have been updated.");
        }
Esempio n. 2
0
        public void PassingAdditionalOptionsToOverrideRunSettingsDriverParamsPasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName             = "edge",
                RS_DeviceGroup             = "edge;win10",
                RS_DriverServerExePath     = "somePath",
                RS_ImplicitWaitTime        = "100",
                RS_LocalExecution          = true,
                RS_LocalExecutionAsService = true
            };

            DriverCapabilities  cap     = new DriverCapabilities(context);
            RunParameterUpdater options = new RunParameterUpdater();

            options.Update(nameof(Constants.RS_BrowserName), Constants.RS_BrowserName)
            .Update(nameof(Constants.RS_DeviceGroup), Constants.RS_DeviceGroup)
            .Update(nameof(Constants.RS_DriverServerExePath), Constants.RS_DriverServerExePath)
            .Update(nameof(Constants.RS_ImplicitWaitTime), Constants.RS_ImplicitWaitTime)
            .Update(nameof(Constants.RS_LocalExecution), Convert.ToBoolean(Constants.RS_LocalExecution))
            .Update(nameof(Constants.RS_LocalExecutionAsService), Convert.ToBoolean(Constants.RS_LocalExecutionAsService));
            cap.OverrideRunSettingsParams(options);
            Assert.AreEqual(context.RS_BrowserName, Constants.RS_BrowserName, $"{nameof(Constants.RS_BrowserName)} should have been updated.");
            Assert.AreEqual(context.RS_DeviceGroup, Constants.RS_DeviceGroup, $"{nameof(Constants.RS_DeviceGroup)} should have been updated.");
            Assert.AreEqual(context.RS_DriverServerExePath, Constants.RS_DriverServerExePath, $"{nameof(Constants.RS_DriverServerExePath)} should have been updated.");
            Assert.AreEqual(context.RS_ImplicitWaitTime, Constants.RS_ImplicitWaitTime, $"{nameof(Constants.RS_ImplicitWaitTime)} should have been updated.");
            Assert.AreEqual(context.RS_LocalExecution, Convert.ToBoolean(Constants.RS_LocalExecution), $"{nameof(Constants.RS_LocalExecution)} should have been updated.");
            Assert.AreEqual(context.RS_LocalExecutionAsService, Convert.ToBoolean(Constants.RS_LocalExecutionAsService), $"{nameof(Constants.RS_LocalExecutionAsService)} should have been updated.");
        }
        public void SupplyingAcceptableCapabilitiesForDriverServiceLaunchesChromeBrowser()
        {
            TestEnvironmentParameters @params = new TestEnvironmentParameters()
            {
                RS_LocalExecution          = true,
                RS_LocalExecutionAsService = true,
                RS_DriverServerExePath     = TestContext.CurrentContext.TestDirectory,
                RS_BrowserName             = "chrome",
                RS_ServerHost       = "localhost",
                RS_ServerPort       = "4278",
                RS_ImplicitWaitTime = "0" //Write unit test for testing empty properties
            };

            DriverService.Start(@params);
            DriverCapabilities caps = new DriverCapabilities(@params);

            caps.GetDriverOptions <ChromeOptions>().AddArgument("--headless"); //Test this in unit test
            WebDriver.Initialize(caps);
            Assert.That(WebDriver.Instance != null, "Driver should have been instantiated successfully");
            Assert.AreEqual("data:,", WebDriver.Instance.Url, "Empty url should have been opened");
            WebDriver.Instance.Navigate().GoToUrl("https://google.com");
            Assert.AreEqual("https://www.google.com/", WebDriver.Instance.Url, "Should have navigated to google.com");
            WebDriver.Dispose();
            DriverService.Dispose();
        }
        public void NoLocalExecutionSetShouldNotStartService()
        {
            TestEnvironmentParameters paramerters = new TestEnvironmentParameters {
                RS_LocalExecution = false
            };

            DriverService.Start(paramerters);
            Assert.Null(paramerters.ServerUri, "Service should not be started when LocalExecution is not set.");
        }
        public ServerCommandExecutor() : this(null, null)
        {
            //Check if the test context contains appropriate parameters, set them if true
            RemoteWebDriver           driver     = WebDriver.Instance;
            TestEnvironmentParameters parameters = WebTestContext.Get <TestEnvironmentParameters>(Constants.TestEnvironmentKey);
            Uri serverUri = parameters.ServerUri;

            sessionId      = driver.SessionId;
            this.serverUri = serverUri;
        }
Esempio n. 6
0
        public void EmptyDeviceGroupParameterThrows()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType = ApplicationType.HYBRID
            };

            Assert.Throws <InvalidCapabilityException>(() => {
                DriverCapabilities caps = new DriverCapabilities(p);
            }, "DeviceGroup is a manadatory parameter and cannot be null or empty");
        }
        /// <summary>
        /// Initializes the Appium driver. Service can be set using .see AppiumServer
        /// for local execution and by setting the .seealso TestRunParameters.LocalExecution,
        /// nodeEXE and AppiumJS path in runsettings file. Set AppiumServerUri for grid or manual server test execution.
        /// To get the instance of the appropriate driver, use the .see "GetInstance" method
        /// </summary>
        /// <param name="capabilities">Capabilities expected of the driver</param>
        public static void Initialize(DriverCapabilities capabilities)
        {
            AppiumDriver <AppiumWebElement> instance;
            TestEnvironmentParameters       TestRunParameters = capabilities.GetEnvironmentContext();
            TimeSpan implicitWaitTimeSpan = TimeSpan.FromSeconds(Convert.ToInt32(TestRunParameters.RS_ImplicitWaitTime));

            instance = InitializeDriver(capabilities);
            instance.Manage().Timeouts().ImplicitWait = implicitWaitTimeSpan;
            Instance = instance;
        }
Esempio n. 8
0
        public void AppiumServiceShouldNotStartIfLocalExecutionIsFalse()
        {
            TestEnvironmentParameters parameters = new TestEnvironmentParameters {
                RS_LocalExecution          = "false",
                RS_LocalExecutionAsService = "true"
            };

            AppiumServer.Start(parameters);
            Assert.False(MobileTestContext.ContainsKey(Constants.AppiumServiceKey), "Service should not have started");
        }
        public void NoBrowserNameShouldThrowOnLocalExecutionAsService()
        {
            TestEnvironmentParameters paramerters = new TestEnvironmentParameters {
                RS_LocalExecution          = true,
                RS_LocalExecutionAsService = true,
            };
            var exception = Assert.Catch <ArgumentNullException>(() => DriverService.Start(paramerters), "Service should not be started when browser name is not set.");

            Assert.That(exception.Message.Contains("RS_BrowserName"), Is.True, "Browser name exception should have been thrown.");
        }
        public ServerCommandExecutor() : this(null, null)
        {
            //Check if the test context contains appropriate parameters, set them if true
            AppiumDriver <AppiumWebElement> driver     = MobileTestContext.Get <AppiumDriver <AppiumWebElement> >(nameof(MobileDriver), false);
            TestEnvironmentParameters       parameters = MobileTestContext.Get <TestEnvironmentParameters>(Constants.TestEnvironmentKey);
            Uri serverUri = parameters.ServerUri;

            this.sessionId = driver.SessionId;
            this.serverUri = serverUri;
        }
Esempio n. 11
0
        public void ProvidingDefaultOrNullSignInIdThrowsForIosNonWebApps()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType     = ApplicationType.HYBRID,
                RS_DeviceGroup = "iOS;Tablet"
            };
            DriverCapabilities caps = new DriverCapabilities(p);

            Assert.Throws <InvalidCapabilityException>(() => caps.MergeCapabilities(new AdditionalDriverOptions()), "Providing null signIn capability should throw.");
        }
Esempio n. 12
0
        public void PassingIEBrowserNameCreatesIECapability()
        {
            TestEnvironmentParameters @params = new TestEnvironmentParameters()
            {
                RS_BrowserName = "ie"
            };
            var cap = new DriverCapabilities(@params);

            Assert.NotNull(cap.GetDriverOptions <InternetExplorerOptions>(), "Should have created IE options.");
            Assert.Null(cap.GetDriverOptions <ChromeOptions>(), "Invalid option should not be resolved.");
        }
Esempio n. 13
0
        public void PassingValidBrowserPasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "Chrome"
            };

            Assert.DoesNotThrow(() => {
                DriverCapabilities cap = new DriverCapabilities(context);
            },
                                $"Valid browser should not throw");
        }
Esempio n. 14
0
        public void PassingSafariBrowserNameCreatesSafariCapability()
        {
            TestEnvironmentParameters @params = new TestEnvironmentParameters()
            {
                RS_BrowserName = "safari"
            };
            var cap = new DriverCapabilities(@params);

            Assert.NotNull(cap.GetDriverOptions <SafariOptions>(), "Should have created safari options.");
            Assert.Null(cap.GetDriverOptions <ChromeOptions>(), "Invalid option should not be resolved.");
        }
Esempio n. 15
0
        public void PassingCapabilityToIEPasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "IE",
                ServerUri      = Helpers.CreateUri("localhost", "1234", "/wd/hub/")
            };
            DriverCapabilities cap = new DriverCapabilities(context);
            var c = cap.GetDriverOptions <InternetExplorerOptions>();

            c.EnableNativeEvents = true;
            Assert.AreEqual(cap.GetDriverOptions <InternetExplorerOptions>().EnableNativeEvents, true, "Capabilitye should have been added for IEOptions");
        }
Esempio n. 16
0
        public void NullBrowserNameOnOverridingShouldThrow()
        {
            TestEnvironmentParameters @params = new TestEnvironmentParameters()
            {
                RS_BrowserName = "chrome"
            };
            var cap = new DriverCapabilities(@params);
            RunParameterUpdater opts = new RunParameterUpdater();

            opts.Update(nameof(Constants.RS_BrowserName), "");
            Assert.Throws <InvalidCapabilityException>(() => cap.MergeCapabilities(opts), "Should not be allowed to create instance if browser name is null or empty");
        }
Esempio n. 17
0
        public void PassingCapabilityToEdgePasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "edge",
                ServerUri      = Helpers.CreateUri("localhost", "1234", "/wd/hub/")
            };
            DriverCapabilities cap = new DriverCapabilities(context);
            var c = cap.GetDriverOptions <EdgeOptions>();

            c.UseInPrivateBrowsing = true;
            Assert.AreEqual(cap.GetDriverOptions <EdgeOptions>().UseInPrivateBrowsing, true, "Capability should have been added/updated for Edge");
        }
Esempio n. 18
0
        public void PassingCapabilityToChromePasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "Chrome",
                ServerUri      = Helpers.CreateUri("localhost", "1234", "/wd/hub/")
            };
            DriverCapabilities cap = new DriverCapabilities(context);
            var c = cap.GetDriverOptions <ChromeOptions>();

            c.PlatformName = "WIN10";
            Assert.AreEqual(cap.GetDriverOptions <ChromeOptions>().PlatformName.ToUpper(), "WIN10", "Argument should have been added from Chrome");
        }
Esempio n. 19
0
        public void PassingInvalidBrowserThrows()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "blowfish"
            };


            Assert.Throws <InvalidCapabilityException>(() => {
                DriverCapabilities cap = new DriverCapabilities(context);
            },
                                                       $" Browser {context.RS_BrowserName} is not supported");
        }
Esempio n. 20
0
        public void NullServerHostOnOverridingShouldThrow()
        {
            TestEnvironmentParameters @params = new TestEnvironmentParameters()
            {
                RS_BrowserName = "chrome"
            };
            var cap = new DriverCapabilities(@params);
            RunParameterUpdater opts = new RunParameterUpdater();

            opts.Update(nameof(@params.ServerUri), null);
            Assert.Throws <ArgumentNullException>(() => cap.MergeCapabilities(opts), "Should not be allowed to create instance if host is null or empty");
        }
Esempio n. 21
0
        public void PassingCapabilityToSafariPasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "safari",
                ServerUri      = Helpers.CreateUri("localhost", "1234", "/wd/hub/")
            };
            DriverCapabilities cap = new DriverCapabilities(context);
            var c = cap.GetDriverOptions <SafariOptions>();

            c.EnableAutomaticInspection = true;
            Assert.AreEqual(cap.GetDriverOptions <SafariOptions>().EnableAutomaticInspection, true, "Capability should have been added for Safari Options");
        }
Esempio n. 22
0
        public void HostNameEmptyThrows()
        {
            TestEnvironmentParameters parameters = new TestEnvironmentParameters {
                RS_LocalExecution          = "true",
                RS_LocalExecutionAsService = "true",
                RS_ServerHost   = "",
                RS_NodeExePath  = Constants.RS_NodeExePath,
                RS_AppiumJSPath = Constants.RS_AppiumJSPath
            };

            Assert.Throws <ArgumentNullException>(() => AppiumServer.Start(parameters), "Empty Hostname should throw.");
        }
        public void NoHostNameShouldThrowOnLocalExecutionAsService()
        {
            TestEnvironmentParameters paramerters = new TestEnvironmentParameters {
                RS_LocalExecution          = true,
                RS_LocalExecutionAsService = true,
                RS_DriverServerExePath     = "some random path",
                RS_BrowserName             = "chrome"
            };
            var exception = Assert.Catch <ArgumentNullException>(() => DriverService.Start(paramerters), "Service should not be started when LocalExecutionAsService is not set.");

            Assert.That(exception.Message.Contains("RS_ServerHost"), Is.True, "Host name exception should have been thrown.");
        }
Esempio n. 24
0
 public void TestSetup()
 {
     parameter = new TestEnvironmentParameters {
         RS_DriverServerExePath     = Path.Combine(TestContext.CurrentContext.TestDirectory),
         RS_LocalExecution          = true,
         RS_LocalExecutionAsService = true,
         RS_ServerHost       = "localhost",
         RS_ServerResource   = Constants.RS_ServerResource,
         RS_ServerPort       = "5546",
         RS_ImplicitWaitTime = Constants.RS_ImplicitWaitTime,
         RS_BrowserName      = "chrome"
     };
 }
        public void InvalidBrowserNameShouldThrowOnLocalExecutionAsService()
        {
            TestEnvironmentParameters paramerters = new TestEnvironmentParameters {
                RS_LocalExecution          = true,
                RS_LocalExecutionAsService = true,
                RS_BrowserName             = "Bionix",
                RS_DriverServerExePath     = "Blah",
                RS_ServerHost = "Localhost",
                RS_ServerPort = "2334"
            };
            var exception = Assert.Catch <DriverServiceException>(() => DriverService.Start(paramerters), "Service should not be started when invalid browser name is provided");

            Assert.That(exception.Message.Contains("Bionix"), Is.True, "Browser name exception should have been thrown.");
        }
Esempio n. 26
0
        public void PassingArgumentToChromePasses()
        {
            var context = new TestEnvironmentParameters {
                RS_BrowserName = "Chrome",
                ServerUri      = Helpers.CreateUri("localhost", "1234", "/wd/hub/")
            };
            DriverCapabilities  cap = new DriverCapabilities(context);
            RunParameterUpdater opt = new RunParameterUpdater();
            string argumentToAdd    = "--somerandomStuff";

            cap.GetDriverOptions <ChromeOptions>().AddArgument(argumentToAdd);
            cap.MergeCapabilities(opt);
            Assert.True(cap.GetDriverOptions <ChromeOptions>().Arguments.IndexOf(argumentToAdd) > 0, "Argument should have been added");
        }
Esempio n. 27
0
        public void SettingBrowserOptionForWebAppPassesPrereqChecksInIOS()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType     = ApplicationType.WEB,
                RS_BrowserName = MobileBrowserType.Safari,
                RS_DeviceGroup = "iOS;Tablet"
            };

            DriverCapabilities          caps       = new DriverCapabilities(p);
            Dictionary <string, object> setOptions = caps.GetDriverOptions().ToDictionary();

            Assert.NotNull(caps.GetDriverOptions(), "Options should be set.");
            Assert.AreEqual(MobileBrowserType.Safari, setOptions["browserName"], "Browser name should be set for web apps");
        }
Esempio n. 28
0
        public void SettingDefaultAppPackageOnIOSThrows()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType     = ApplicationType.NATIVE,
                RS_DeviceGroup = "iOS;Tablet",
                RS_AppPackage  = "io.android.testapp"
            };

            DriverCapabilities          caps       = new DriverCapabilities(p);
            Dictionary <string, object> setOptions = caps.GetDriverOptions().ToDictionary();

            Assert.NotNull(caps.GetDriverOptions(), "Options should be set.");
            Assert.Catch <InvalidCapabilityException>(() => caps.PreReqChecks(), "Invalid app name allowed to pass");
        }
Esempio n. 29
0
        public void SettingDefaultAppActivityInHybridAppOnAndroidThrows()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType     = ApplicationType.NATIVE,
                RS_DeviceGroup = "Android;Tablet",
                RS_AppPackage  = "some.random.app",
                RS_AppActivity = ".HomeScreenActivity"
            };

            DriverCapabilities          caps       = new DriverCapabilities(p);
            Dictionary <string, object> setOptions = caps.GetDriverOptions().ToDictionary();

            Assert.NotNull(caps.GetDriverOptions(), "Options should be set.");
            Assert.Catch <InvalidCapabilityException>(() => caps.PreReqChecks(), "Invalid app activity allowed to pass");
        }
Esempio n. 30
0
        public void ProvidingBrowserNameAndNoAppPackageForHybridAppThrowsForAndroid()
        {
            TestEnvironmentParameters p = new TestEnvironmentParameters {
                RS_AppType     = ApplicationType.HYBRID,
                RS_BrowserName = MobileBrowserType.Chrome,
                RS_DeviceGroup = "Android;Tablet",
            };

            DriverCapabilities          caps       = new DriverCapabilities(p);
            Dictionary <string, object> setOptions = caps.GetDriverOptions().ToDictionary();

            Assert.NotNull(caps.GetDriverOptions(), "Options should be set.");
            Assert.False(setOptions.ContainsKey("browserName"), "Browser name should be null for hybrid apps");
            Assert.Throws <InvalidCapabilityException>(() => caps.PreReqChecks(), "Prereq checks should throw");
        }