コード例 #1
0
 public void ContextValueSetAndGetPasses()
 {
     Assert.DoesNotThrow(() => {
         MobileTestContext.Set("testKey", "testValue");
         MobileTestContext.Get <string>("testKey", false);
     }, "Retrieving set value should not throw.");
 }
コード例 #2
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");
        }
コード例 #3
0
 public void TearDown()
 {
     if (MobileTestContext.ContainsKey(Constants.AppiumServerLogFileKey))
     {
         if (File.Exists(Constants.AppiumServerLogFileKey))
         {
             File.Delete(Constants.AppiumServerLogFileKey);
         }
     }
     MobileTestContext.Dispose();
 }
コード例 #4
0
 public static void Dispose()
 {
     try {
         if (Instance != null)
         {
             Instance.Quit(); //Calls driver dispose behind the scenes.
         }
         MobileTestContext.Dispose();
     } catch (Exception ex) {
         TestContext.WriteLine($"Failed to disposed off driver session: {ex.Message}");
     }
 }
コード例 #5
0
 public virtual void TestSetup()
 {
     //Start the service if needed
     AppiumServer.Start(TestEnvironmentParameters);
     //Set user provided options.
     MobileTestContext.Set(Constants.AppiumAdditionalOptionsKey, AdditionalCapabilities);
     Capabilities = new DriverCapabilities(TestEnvironmentParameters);
     //Merge user provided options to existing default capabilities.
     Capabilities.MergeCapabilities(MobileTestContext.Get <AdditionalDriverOptions>(Constants.AppiumAdditionalOptionsKey, false));
     // Write Runsettings to log file
     TestLogs.WriteLogSection("Original Test Run Parameters", () => TestLogs.Write(this.TestEnvironmentParameters.ToString()));
     MobileDriver.Initialize(Capabilities);
     //Write device configuration to log file
     TestLogs.WriteLogSection("DUT Configuration", () => TestLogs.Write(MobileDriver.Instance.Capabilities.ToString()));
     //Capture enviroment parameters for all futures uses.
     MobileTestContext.Set(Constants.TestEnvironmentKey, TestEnvironmentParameters);
     TestLogs.AddSection($"Test {TestContext.CurrentContext.Test.Name} Starts");
 }
コード例 #6
0
        public void SecondAppiumServiceStartsIfLocalExecutionAndLocalExecutionAsServiceAreTrue()
        {
            TestEnvironmentParameters parameters = new TestEnvironmentParameters {
                RS_LocalExecution          = "true",
                RS_LocalExecutionAsService = "true",
                RS_ServerHost   = "127.0.0.1",
                RS_NodeExePath  = Constants.RS_NodeExePath,
                RS_AppiumJSPath = Constants.RS_AppiumJSPath,
                RS_ServerPort   = "0000"
            };

            AppiumServer.Start(parameters);
            Uri serviceUri = parameters.ServerUri;

            Assert.True(MobileTestContext.ContainsKey(Constants.AppiumServiceKey), "Service should have started");
            Assert.NotNull(serviceUri, "Service should not be null.");
            Assert.AreEqual(serviceUri, $"http://{Constants.RS_ServerHost}:{parameters.RS_ServerPort}{Constants.RS_ServerResource}", "Service Url does not match default Url");
            Assert.AreNotEqual(parameters.RS_ServerPort, firstTestPortNumber, "Service should start on different port numbers");
            Console.WriteLine(serviceUri.AbsoluteUri);
        }
コード例 #7
0
 public void Setup()
 {
     MobileTestContext.Set(nameof(Constants.DevelopmentMode), "true");
 }
コード例 #8
0
 public void RetreivingNonExistentContextValueThrowsByDefault()
 {
     Assert.Catch <KeyNotFoundException>(() => MobileTestContext.Get <string>("test"), "No key set in thread context must throw by default");
 }
コード例 #9
0
 public void RetreivingNonExistentContextValueDoesNotThrowIfFlagSet()
 {
     Assert.DoesNotThrow(() => {
         MobileTestContext.Get <string>("test", false);
     }, "Fetching non existent value should not throw if throwOnNotFound flag is false");
 }
コード例 #10
0
 public static void Dispose()
 {
     MobileTestContext.Get <AppiumLocalService>(Constants.AppiumServiceKey, false)?.Dispose();
 }
コード例 #11
0
        /// <summary>
        /// Start Appium Server for local execution. Updates the ref parameter <seealso cref=" TestEnvironmentParameters.ServerUri"/> accordingly and sets up the MobileTestContext with parameter with key <see cref="Constants.AppiumServiceKey"/> of type AppiumLocalService
        /// </summary>
        /// <param name="nodeExePath"></param>
        /// <param name="appiumJSPath"></param>
        public static void Start(TestEnvironmentParameters parameters)
        {
            if (!Convert.ToBoolean(parameters.RS_LocalExecution))
            {
                return;
            }
            if (!Convert.ToBoolean(parameters.RS_LocalExecutionAsService))
            {
                return;
            }
            if (string.IsNullOrEmpty(parameters.RS_NodeExePath))
            {
                throw new ArgumentNullException($" [{nameof(parameters.RS_NodeExePath)}] is mandatory for local execution");
            }
            if (string.IsNullOrEmpty(parameters.RS_AppiumJSPath))
            {
                throw new ArgumentNullException($" [{nameof(parameters.RS_AppiumJSPath)}] is mandatory for local execution");
            }
            if (string.IsNullOrEmpty(parameters.RS_ServerHost))
            {
                throw new ArgumentNullException($" [{nameof(parameters.RS_ServerHost)}] is mandatory for local execution");
            }
            string nodeExePath              = parameters.RS_NodeExePath;
            string appiumJSPath             = parameters.RS_AppiumJSPath;
            string serverIP                 = parameters.RS_ServerHost;
            bool   autoDownloadChromeDriver = Convert.ToBoolean(parameters.RS_AutoDownloadChromeDriver ?? "false");
            AppiumServiceBuilder builder    = new AppiumServiceBuilder();
            OptionCollector      option     = new OptionCollector();

            option.AddArguments(new KeyValuePair <string, string>(
                                    "--relaxed-security", string.Empty));
            option.AddArguments(new KeyValuePair <string, string>(
                                    "--allow-insecure", "adb_shell"));
            builder
            .UsingAnyFreePort()
            //.WithLogFile(new FileInfo(logFilePath))
            .UsingDriverExecutable(new FileInfo(nodeExePath))
            .WithAppiumJS(new FileInfo(appiumJSPath))
            .WithStartUpTimeOut(TimeSpan.FromSeconds(60))
            .WithIPAddress(serverIP)
            .WithArguments(option);

            if (autoDownloadChromeDriver)
            {
                KeyValuePair <string, string> argument = new KeyValuePair <string, string>("--allow-insecure", "chromedriver_autodownload");
                option.AddArguments(argument);
                builder.WithArguments(option);
            }

            AppiumLocalService service;

            try {
                service = builder.Build();
                service.Start();
                //MobileTestContext.Set(Constants.AppiumServerLogFileKey, logFilePath);
            } catch (Exception e) {
                throw new AppiumServiceException($"Cannot start appium server.Exception:\n{e}");
            }
            parameters.ServerUri     = service.ServiceUrl;
            parameters.RS_ServerPort = service.ServiceUrl.Port.ToString();
            MobileTestContext.Set(Constants.AppiumServiceKey, service);
        }