Esempio n. 1
0
        public void IniciarTeste()
        {
            var options = new AppiumOptions();
            AppiumServiceBuilder builder = new AppiumServiceBuilder();
            AppiumLocalService   service = builder.Build();

            service.Start();

            options.AddAdditionalCapability("platformName", "Android");
            //options.AddAdditionalCapability("deviceName", "nexus_5_7.1.1");
            options.AddAdditionalCapability("deviceName", "Emulator");
            options.AddAdditionalCapability("automationName", "UiAutomator2");
            //options.AddAdditionalCapability("app", "<path to apk>");

            /*
             * options.AddAdditionalCapability("appPackage", "com.android.calculator2");
             * options.AddAdditionalCapability("appActivity", "com.android.calculator2.Calculator");
             *
             * //*
             * options.AddAdditionalCapability("appPackage", "com.google.android.apps.messaging");
             * options.AddAdditionalCapability("appActivity", "com.google.android.apps.messaging.ui.ConversationListActivity");
             */

            options.AddAdditionalCapability("appPackage", "br.com.unimed.pr.hom.cliente");
            options.AddAdditionalCapability("appActivity", "br.com.unimed.pr.hom.cliente.MainActivity");

            if (usaRemoteWebDriver)
            {
                driver = new AndroidDriver <AndroidElement>(new Uri(urlRemoteWebDriver), options, TimeSpan.FromMinutes(3));
            }
            else
            {
                driver = new AndroidDriver <AndroidElement>(builder, options, TimeSpan.FromMinutes(3));
            }
        }
Esempio n. 2
0
        public void CheckThatServiseIsNotRunWhenTheCreatingOfANewSessionIsFailed()
        {
            var capabilities = Env.ServerIsRemote()
                ? //it will be a cause of error
                               Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"))
                : Caps.GetAndroidUIAutomatorCaps(Apps.Get("androidApiDemos"));

            capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone Simulator");
            capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, MobilePlatform.IOS);

            var builder = new AppiumServiceBuilder();
            var service = builder.Build();

            service.Start();

            IOSDriver <AppiumWebElement> driver = null;

            try
            {
                try
                {
                    driver = new IOSDriver <AppiumWebElement>(service, capabilities);
                }
                catch (Exception e)
                {
                    Assert.IsTrue(!service.IsRunning);
                    return;
                }
                throw new Exception("Any exception was expected");
            }
            finally
            {
                driver?.Quit();
            }
        }
Esempio n. 3
0
        public static void StartServer()
        {
            var appiumLocalService = new AppiumServiceBuilder();

            appiumLocalService.UsingPort(GlobalVar.Port);
            appiumLocalService.WithIPAddress(GlobalVar.IPAddress.ToString());
            appiumLocalService.Build().Start();
        }
Esempio n. 4
0
        public void Setup()
        {
            AppiumOptions capabilities = new AppiumOptions();

            capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");

            AppiumServiceBuilder builder = new AppiumServiceBuilder();
            AppiumLocalService   service = builder.Build();

            service.Start();

            driver = new AndroidDriver <AndroidElement>(service, capabilities);
            // driver = new IOSDriver<IOSElement>(new Uri("http://localhost:4723/wd/hub"), capabilities);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
        }
        public void CheckThatServiseIsNotRunWhenTheCreatingOfANewSessionIsFailed()
        {
            string app = Apps.get("androidApiDemos");

            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability(MobileCapabilityType.DeviceName, "iPhone Simulator");

            OptionCollector argCollector = new OptionCollector().AddArguments(GeneralOptionList.App(app)) //it will be a cause of error
                                                                                                          //that is expected
                                           .AddArguments(GeneralOptionList.AutomationName(AutomationName.Appium)).AddArguments(GeneralOptionList.PlatformName("Android"));

            AppiumServiceBuilder builder = new AppiumServiceBuilder().WithArguments(argCollector);
            AppiumLocalService   service = builder.Build();

            service.Start();

            IOSDriver <AppiumWebElement> driver = null;

            try
            {
                try
                {
                    driver = new IOSDriver <AppiumWebElement>(service, capabilities);
                }
                catch (Exception e)
                {
                    Assert.IsTrue(!service.IsRunning);
                    return;
                }
                throw new Exception("Any exception was expected");
            }
            finally
            {
                if (driver != null)
                {
                    driver.Quit();
                }
            }
        }
Esempio n. 6
0
        public void CheckThatServiseIsNotRunWhenTheCreatingOfANewSessionIsFailed()
        {
            DesiredCapabilities capabilities = Env.isSauce()
                ? //it will be a cause of error
                                               Caps.getAndroid501Caps(Apps.get("androidApiDemos"))
                : Caps.getAndroid19Caps(Apps.get("androidApiDemos"));

            capabilities.SetCapability(MobileCapabilityType.DeviceName, "iPhone Simulator");
            capabilities.SetCapability(MobileCapabilityType.PlatformName, MobilePlatform.IOS);

            AppiumServiceBuilder builder = new AppiumServiceBuilder();
            AppiumLocalService   service = builder.Build();

            service.Start();

            IOSDriver <AppiumWebElement> driver = null;

            try
            {
                try
                {
                    driver = new IOSDriver <AppiumWebElement>(service, capabilities);
                }
                catch (Exception e)
                {
                    Assert.IsTrue(!service.IsRunning);
                    return;
                }
                throw new Exception("Any exception was expected");
            }
            finally
            {
                if (driver != null)
                {
                    driver.Quit();
                }
            }
        }
Esempio n. 7
0
 public AppiumDriver(AppiumServiceBuilder builder, ICapabilities appiumOptions, TimeSpan commandTimeout)
     : this(builder.Build(), appiumOptions, commandTimeout)
 {
 }
Esempio n. 8
0
 public AppiumDriver(AppiumServiceBuilder builder, ICapabilities appiumOptions)
     : this(builder.Build(), appiumOptions)
 {
 }
Esempio n. 9
0
 public AppiumDriver(AppiumServiceBuilder builder, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
     : this(builder.Build(), desiredCapabilities, commandTimeout)
 {
 }
Esempio n. 10
0
 public AppiumDriver(AppiumServiceBuilder builder, ICapabilities desiredCapabilities)
     : this(builder.Build(), desiredCapabilities)
 {
 }
Esempio n. 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);
        }