public void AppiumServerRun(int pThreadIndex) { try { OptionCollector args = new OptionCollector().AddArguments(GeneralOptionList.OverrideSession()); args.AddArguments(AndroidOptionList.BootstrapPort((bootstrapPort + pThreadIndex * 2).ToString())); args.AddArguments(AndroidOptionList.SelendroidPort((selendroidPort + pThreadIndex * 2).ToString())); service = new AppiumServiceBuilder().UsingPort(appiumServerPort + pThreadIndex * 2).WithArguments(args).Build(); service.Start(); } catch (Exception e) { _Log.PrintTaskStatus(pThreadIndex, "\tCreate the Appium Server Exception : " + e.Message); } }
private AndroidDriver <AppiumWebElement> StartApp() { System.Environment.SetEnvironmentVariable("ANDROID_HOME", @"C:\Users\marko\AppData\Local\Android\Sdk"); System.Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files\Java\jdk1.8.0_161\"); var cappabilities = new AppiumOptions(); cappabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "52003b08eae92517"); cappabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "UiAutomator2"); var currentPath = Directory.GetCurrentDirectory(); Console.WriteLine($"Current path: {currentPath}"); var packagePath = Path.Combine(currentPath, @"..\..\..\TestApp\Interval Timer_v2.2.2_apkpure.com.apk"); packagePath = Path.GetFullPath(packagePath); Console.WriteLine($"package path: {packagePath}"); cappabilities.AddAdditionalCapability(MobileCapabilityType.App, packagePath); cappabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, "cc.dreamspark.intervaltimer"); cappabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, ".MainActivity"); var serveroptions = new OptionCollector(); var relaxeSecurityOption = new KeyValuePair <string, string>("--relaxed-security", ""); serveroptions.AddArguments(relaxeSecurityOption); var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().WithArguments(serveroptions).Build(); _appiumLocalService.Start(); var driver = new AndroidDriver <AppiumWebElement>(_appiumLocalService, cappabilities); return(driver); }
public static void ClassInit(TestContext context) { // Start Appium Server var avdOptions = new KeyValuePair <string, string>("--avd", "Emulator-Api19-Default"); var avdParamsOptions = new KeyValuePair <string, string>("--avd-args", "\"-scale 0.50\""); OptionCollector args = new OptionCollector(); args.AddArguments(avdOptions); args.AddArguments(avdParamsOptions); service = new AppiumServiceBuilder().WithArguments(args).UsingAnyFreePort().Build(); service.Start(); Assert.IsTrue(service.IsRunning); // Start Appium Client DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.SetCapability("deviceName", "Android Emulator"); capabilities.SetCapability("platformName", "Android"); capabilities.SetCapability("app", "C:\\Git\\qa-academy\\2015\\MobileTesting\\testapp\\android-rottentomatoes-demo-debug.apk"); driver = new AndroidDriver <AndroidElement>(service.ServiceUrl, capabilities); }
public AppiumLocalService StartAppiumLocalService() { var severoptions = new OptionCollector(); var relaxedSecurityOptions = new KeyValuePair <string, string>("--relaxed-security", ""); severoptions.AddArguments(relaxedSecurityOptions); _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort() .Build(); if (!_appiumLocalService.IsRunning) { _appiumLocalService.Start(); } return(_appiumLocalService); }
// handler: arguments private void SetArguments() { // exit conditions var compliance = Arguments?.Count > 0; if (!compliance) { return; } // set properties options ??= new OptionCollector(); foreach (var argumet in Arguments) { var argumentOption = new KeyValuePair <string, string>(argumet.Key, argumet.Value); options.AddArguments(argumentOption); } serviceBuilder.WithArguments(options); }
private AndroidDriver <AppiumWebElement> StartApp() { System.Environment.SetEnvironmentVariable("ANDROID_HOME", @"C:\Program Files (x86)\Android\android-sdk"); System.Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25"); var capabilities = new AppiumOptions(); // automatic start of the emulator if not running capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.Avd, "demo_device"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AvdArgs, "-no-boot-anim -no-snapshot-load"); capabilities.AddAdditionalCapability(MobileCapabilityType.FullReset, true); // connecting to a device or emulator capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "emulator-5554"); capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "UiAutomator2"); // specifyig which app we want to install and launch var currentPath = Directory.GetCurrentDirectory(); Console.WriteLine($"Current path: {currentPath}"); var packagePath = Path.Combine(currentPath, @"..\..\..\AppsToTest\com.fluentbytes.carvedrock-x86.apk"); packagePath = Path.GetFullPath(packagePath); Console.WriteLine($"Package path: {packagePath}"); capabilities.AddAdditionalCapability(MobileCapabilityType.App, packagePath); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, "com.fluentbytes.carvedrock"); capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, "crc641782d5af3c9cf50a.MainActivity"); // additional wait time in case we have a clean emulator and need to wait for the install capabilities.AddAdditionalCapability("appWaitDuration", 4800000); // specify startup flags appium server to execute adb shell commands var serveroptions = new OptionCollector(); var relaxedSecurityOption = new KeyValuePair <string, string>("--relaxed-security", ""); serveroptions.AddArguments(relaxedSecurityOption); var _appiumLocalService = new AppiumServiceBuilder().UsingAnyFreePort().WithArguments(serveroptions).Build(); _appiumLocalService.Start();; var driver = new AndroidDriver <AppiumWebElement>(_appiumLocalService, capabilities); return(driver); }
/// <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); }