예제 #1
0
        public void Init()
        {
            NameValueCollection caps    = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection;
            NameValueCollection devices = ConfigurationManager.GetSection("environments/" + device) as NameValueCollection;

            AppiumOptions options = new AppiumOptions();

            foreach (string key in caps.AllKeys)
            {
                options.AddAdditionalCapability(key, caps[key]);
            }

            foreach (string key in devices.AllKeys)
            {
                options.AddAdditionalCapability(key, devices[key]);
            }

            String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");

            if (username == null)
            {
                username = ConfigurationManager.AppSettings.Get("user");
            }

            String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");

            if (accesskey == null)
            {
                accesskey = ConfigurationManager.AppSettings.Get("key");
            }

            options.AddAdditionalCapability("browserstack.user", username);
            options.AddAdditionalCapability("browserstack.key", accesskey);

            String appId = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID");

            if (appId != null)
            {
                options.AddAdditionalCapability("app", appId);
            }

            // if the platform is Windows, enable local testing fropm within the test
            // for Mac and GNU/Linux, run the local binary manually to enable local testing (see the docs)
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
                options.ToCapabilities().HasCapability("browserstack.local") &&
                options.ToCapabilities().GetCapability("browserstack.local").ToString() == "true")
            {
                browserStackLocal = new Local();
                List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("key", accesskey)
                };
                browserStackLocal.start(bsLocalArgs);
            }

            Uri uri = new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/");

            driver = new AndroidDriver <AndroidElement>(uri, options);
        }
예제 #2
0
        public static void beforeFeature()
        {
            var desiredCaps = new AppiumOptions
            {
                PlatformName = "Android"
                               // PlatformName = "iOS"
            };

            //Credentials from setting file named properties
            desiredCaps.AddAdditionalCapability("user", PerfectoUser);
            desiredCaps.AddAdditionalCapability("securityToken", PerfectoToken);


            desiredCaps.AddAdditionalCapability("platformName", "Android");
            desiredCaps.AddAdditionalCapability("model", "Galaxy S6");

            Uri url = new Uri(string.Format("http://{0}/nexperience/perfectomobile/wd/hub/fast", PerfectoHost));

            if (desiredCaps.ToCapabilities().GetCapability("platformName").Equals("Android"))
            {
                driver = new AndroidDriver <IWebElement>(url, desiredCaps);
            }
            else
            {
                driver = new IOSDriver <IWebElement>(url, desiredCaps);
            }
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);

            reportingClient = CreateReportingClient();
        }
예제 #3
0
        public override IWebDriver InitialiseForLocal()
        {
            var chromePath = $"{BuildPath}/chromedriver";
            var options    = new AppiumOptions();

            options.AddAdditionalCapability("avd", DeviceName);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, DeviceName);
            options.AddAdditionalCapability(MobileCapabilityType.Orientation, Orientation.ToString());
            options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "Chrome");
            options.AddAdditionalCapability(AndroidMobileCapabilityType.ChromedriverExecutable, chromePath);
            return(new RemoteWebDriver(Uri, options.ToCapabilities(), LocalAppiumTimeout));
        }
예제 #4
0
        public override RemoteWebDriver InitialiseForSauceLabs()
        {
            var options = new AppiumOptions();

            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, DeviceName);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "Chrome");
            options.AddAdditionalCapability(MobileCapabilityType.AppiumVersion, AppiumVersion);
            options.AddAdditionalCapability(MobileCapabilityType.Orientation, Orientation.ToString());
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, PlatformVersion);

            foreach (var(key, value) in SauceOptions)
            {
                options.AddAdditionalCapability(key, value);
            }

            return(new RemoteWebDriver(Uri, options.ToCapabilities()));
        }
        public override IWebDriver InitialiseForLocal()
        {
            var options = new AppiumOptions();

            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, DeviceName);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
            options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "Safari");
            options.AddAdditionalCapability(MobileCapabilityType.Orientation, Orientation.ToString());
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, PlatformVersion);

            if (ResetDeviceBetweenTests)
            {
                LocalAppiumTimeout *= 4;
                options.AddAdditionalCapability(MobileCapabilityType.FullReset, true);
            }

            return(new RemoteWebDriver(Uri, options.ToCapabilities(), LocalAppiumTimeout));
        }
예제 #6
0
        static void Main(string[] args)
        {
            Local browserStackLocal = null;

            AppiumOptions appiumOptions = new AppiumOptions();

            // Set your BrowserStack access credentials
            appiumOptions.AddAdditionalCapability("browserstack.user", userName);
            appiumOptions.AddAdditionalCapability("browserstack.key", accessKey);


            // Set URL of the application under test
            appiumOptions.AddAdditionalCapability("app", "bs://<app_id>");

            // Specify device and os_version
            appiumOptions.AddAdditionalCapability("device", "iPhone 11 Pro");
            appiumOptions.AddAdditionalCapability("os_version", "13");

            // Set browserstack.local capability as true
            appiumOptions.AddAdditionalCapability("browserstack.local", "true");

            // Specify the platform name
            appiumOptions.PlatformName = "iOS";

            // Set other BrowserStack capabilities
            appiumOptions.AddAdditionalCapability("project", "First CSharp project");
            appiumOptions.AddAdditionalCapability("build", "CSharp iOS local");
            appiumOptions.AddAdditionalCapability("name", "local_test");



            // if the platform is Windows, enable local testing fropm within the test
            // for Mac and GNU/Linux, run the local binary manually to enable local testing (see the docs)
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
                appiumOptions.ToCapabilities().HasCapability("browserstack.local") &&
                appiumOptions.ToCapabilities().GetCapability("browserstack.local").ToString() == "true")
            {
                browserStackLocal = new Local();
                List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("key", accessKey)
                };
                browserStackLocal.start(bsLocalArgs);
            }


            // Initialize the remote Webdriver using BrowserStack remote URL
            // and desired capabilities defined above
            IOSDriver <IOSElement> driver = new IOSDriver <IOSElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), appiumOptions);

            //Test case for sample iOS Local app.
            // If you have uploaded your app, update the test case here.
            IOSElement testButton = (IOSElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("TestBrowserStackLocal"))
                );

            testButton.Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.TextToBePresentInElementValue(driver.FindElement(MobileBy.AccessibilityId("ResultBrowserStackLocal")), "Response is: Up and running"));
            IOSElement resultElement = (IOSElement)driver.FindElement(MobileBy.AccessibilityId("ResultBrowserStackLocal"));

            Console.WriteLine(resultElement.Text);

            //Invoke driver.quit() after the test is done to indicate that the test is completed.
            driver.Quit();

            //Stop the BrowserStack Local binary
            if (browserStackLocal != null)
            {
                browserStackLocal.stop();
            }
        }
예제 #7
0
        private static IWebDriver InitOnSaucelabs(string deviceName, string platformVersion, ScreenOrientation deviceOrientation, string testName, string platformName, string browserName)
        {
            AppiumOptions options = new AppiumOptions();

            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, platformName);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, platformVersion);
            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, deviceName);
            options.AddAdditionalCapability(MobileCapabilityType.BrowserName, browserName);
            options.AddAdditionalCapability("deviceOrientation", deviceOrientation.ToString().ToLower());

            options.AddAdditionalCapability("username", TestDataProvider.SAUCE_USERNAME);
            options.AddAdditionalCapability("accesskey", TestDataProvider.SAUCE_ACCESS_KEY);

            options.AddAdditionalCapability("name", testName);
            options.AddAdditionalCapability("idleTimeout", 360);

            options.PlatformName = platformName;

            IWebDriver webDriver = SeleniumUtils.RetryCreateWebDriver(() =>
            {
                IWebDriver driver = new RemoteWebDriver(new Uri(TestDataProvider.SAUCE_SELENIUM_URL), options.ToCapabilities(), TimeSpan.FromMinutes(4));
                return(driver);
            });

            return(webDriver);
        }
예제 #8
0
        private static void RunOnIos_(Eyes eyes)
        {
            AppiumOptions options = new AppiumOptions();

            options.AddAdditionalCapability("name", "Open Check Close X2 (B)");

            options.AddAdditionalCapability("username", TestDataProvider.SAUCE_USERNAME);
            options.AddAdditionalCapability("accessKey", TestDataProvider.SAUCE_ACCESS_KEY);

            options.AddAdditionalCapability("deviceName", "iPad Simulator");
            options.AddAdditionalCapability("deviceOrientation", "portrait");
            options.AddAdditionalCapability("platformName", "iOS");
            options.AddAdditionalCapability("platformVersion", "12.2");
            options.AddAdditionalCapability("browserName", "Safari");

            RemoteWebDriver driver = new RemoteWebDriver(new Uri(TestDataProvider.SAUCE_SELENIUM_URL), options.ToCapabilities(), TimeSpan.FromMinutes(3));

            try
            {
                IWebDriver eyesDriver = eyes.Open(driver, "Applitools", "Open Check Close X2 SauceLabs (B)");
                driver.Url = "https://www.google.com";
                eyes.Check("Test iOS", Target.Window().SendDom(false));
                eyes.Close(false);
            }
            finally
            {
                // Close the browser.
                driver.Quit();

                // If the test was aborted before eyes.Close was called, ends the test as aborted.
                eyes.Abort();
            }
        }
예제 #9
0
        private static void RunOnAndroid_(Eyes eyes)
        {
            AppiumOptions options = new AppiumOptions();

            options.AddAdditionalCapability("name", "Open Check Close X2 (A)");

            options.AddAdditionalCapability("username", TestDataProvider.SAUCE_USERNAME);
            options.AddAdditionalCapability("accesskey", TestDataProvider.SAUCE_ACCESS_KEY);

            options.AddAdditionalCapability("deviceName", "Samsung Galaxy Tab S3 GoogleAPI Emulator");
            options.AddAdditionalCapability("deviceOrientation", "landscape");
            options.AddAdditionalCapability("platformName", "Android");
            options.AddAdditionalCapability("platformVersion", "8.1");
            options.AddAdditionalCapability("browserName", "Chrome");

            RemoteWebDriver driver = new RemoteWebDriver(new Uri(TestDataProvider.SAUCE_SELENIUM_URL), options.ToCapabilities(), TimeSpan.FromMinutes(3));

            //*************

            try
            {
                IWebDriver eyesDriver = eyes.Open(driver, "Applitools", "Open Check Close X2 SauceLabs (A)");
                eyesDriver.Url = "https://www.applitools.com";
                eyes.Check("Test Android", Target.Window().SendDom(false));
                eyes.Close(false);
            }
            finally
            {
                // Close the browser.
                driver.Quit();

                // If the test was aborted before eyes.Close was called, ends the test as aborted.
                eyes.Abort();
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            Local browserStackLocal = null;

            AppiumOptions appiumOptions = new AppiumOptions();

            // Set your BrowserStack access credentials
            appiumOptions.AddAdditionalCapability("browserstack.user", userName);
            appiumOptions.AddAdditionalCapability("browserstack.key", accessKey);


            // Set URL of the application under test
            appiumOptions.AddAdditionalCapability("app", "bs://<app-id>");

            // Specify device and os_version
            appiumOptions.AddAdditionalCapability("device", "Google Pixel 3");
            appiumOptions.AddAdditionalCapability("os_version", "9.0");

            appiumOptions.AddAdditionalCapability("browserstack.local", "true");

            // Specify the platform name
            appiumOptions.PlatformName = "Android";

            // Set other BrowserStack capabilities
            appiumOptions.AddAdditionalCapability("project", "First CSharp project");
            appiumOptions.AddAdditionalCapability("build", "CSharp Android local");
            appiumOptions.AddAdditionalCapability("name", "local_test");


            // if the platform is Windows, enable local testing fropm within the test
            // for Mac and GNU/Linux, run the local binary manually to enable local testing (see the docs)
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
                appiumOptions.ToCapabilities().HasCapability("browserstack.local") &&
                appiumOptions.ToCapabilities().GetCapability("browserstack.local").ToString() == "true")
            {
                browserStackLocal = new Local();
                List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("key", accessKey)
                };
                browserStackLocal.start(bsLocalArgs);
            }


            // Initialize the remote Webdriver using BrowserStack remote URL
            // and desired capabilities defined above
            AndroidDriver <AndroidElement> driver = new AndroidDriver <AndroidElement>(
                new Uri("http://hub-cloud.browserstack.com/wd/hub"), appiumOptions);

            // Test case for the BrowserStack sample Android Local app.
            // If you have uploaded your app, update the test case here.
            AndroidElement searchElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.Id("com.example.android.basicnetworking:id/test_action"))
                );

            searchElement.Click();
            AndroidElement insertTextElement = (AndroidElement) new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(
                SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(MobileBy.ClassName("android.widget.TextView"))
                );

            AndroidElement testElement = null;

            IReadOnlyList <AndroidElement> allTextViewElements = driver.FindElementsByClassName("android.widget.TextView");

            System.Threading.Thread.Sleep(5000);
            foreach (AndroidElement textElement in allTextViewElements)
            {
                if (textElement.Text.Contains("The active connection is"))
                {
                    testElement = textElement;
                }
            }

            Console.WriteLine(testElement.Text);
            // Invoke driver.quit() after the test is done to indicate the test is completed.
            driver.Quit();

            // Stop the BrowserStack Local Binary.
            if (browserStackLocal != null)
            {
                browserStackLocal.stop();
            }
        }