Beispiel #1
0
 public static void Setup(TestContext context)
 {
     if (session == null)
     {
         var appiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();
         appiumOptions.AddAdditionalCapability("app", WpfAppId);
         appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
         session = new OpenQA.Selenium.Appium.Windows.WindowsDriver <OpenQA.Selenium.Appium.Windows.WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
     }
 }
Beispiel #2
0
        private WindowsDriver <WindowsElement> GetLoginWindowSession()
        {
            var loginWindowAppiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();

            loginWindowAppiumOptions.AddAdditionalCapability("app",
                                                             @"D:\Safe-Cloud-File\DesktopApp-Example\bin\Debug\DesktopApp-Example.exe");
            loginWindowAppiumOptions.AddAdditionalCapability("appWorkingDir",
                                                             @"D:\Safe-Cloud-File\DesktopApp-Example\bin\Debug\");
            var loginWindowSesion =
                new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), loginWindowAppiumOptions);

            loginWindowSesion.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            return(loginWindowSesion);
        }
Beispiel #3
0
        private void PopulateCapabilities(OpenQA.Selenium.Appium.AppiumOptions inOptions, IDictionary <string, string> withWellKnownCapabilities, IDictionary <string, object> from)
        {
            if (null == withWellKnownCapabilities)
            {
                throw new ArgumentNullException(nameof(withWellKnownCapabilities));
            }
            if (null == inOptions)
            {
                throw new ArgumentNullException(nameof(inOptions));
            }

            if (null == from)
            {
                return;
            }

            from.ToList().ForEach(pair =>
            {
                if (pair.Key.StartsWith("!"))
                {
                    return;
                }

                // NOTE: Environment Variable overrides will populate AppiumSettings with the case of the environment variable.
                //       ie: ...__APP will set the APP capability (it needs to be 'app')
                var candidateKey = pair.Key;

                var keyIsKnown = withWellKnownCapabilities.ContainsKey(candidateKey);
                if (keyIsKnown)
                {
                    candidateKey = withWellKnownCapabilities.Keys.First(k => string.Compare(k, pair.Key, StringComparison.InvariantCultureIgnoreCase) == 0);
                }

                if (!keyIsKnown)
                {
                    // As the key is not known - do not coerce it.
                    inOptions.AddAdditionalOption(candidateKey, pair.Value);
                }
                else
                {
                    inOptions.AddAdditionalOption(candidateKey, CoerceValueToType(candidateKey, withWellKnownCapabilities[candidateKey], pair.Value));
                }
            });
        }
Beispiel #4
0
        public OpenQA.Selenium.Appium.AppiumOptions ToAppiumOptions(AppiumSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var result = new OpenQA.Selenium.Appium.AppiumOptions();

            // General Capabilities
            PopulateCapabilities(inOptions: result, withWellKnownCapabilities: RecognizedGeneralCapabilities, from: settings?.DeviceSettings?.Options?.GeneralCapabilities);

            // Android Capabilities
            PopulateCapabilities(inOptions: result, withWellKnownCapabilities: RecognizedAndroidCapabilities, from: settings?.DeviceSettings?.Options?.AndroidCapabilities);

            // UIAutomatorCapabilities
            PopulateCapabilities(inOptions: result, withWellKnownCapabilities: RecognizedUIAutomatorCapabilities, from: settings?.DeviceSettings?.Options?.UIAutomatorCapabilities);

            return(result);
        }
Beispiel #5
0
        public void Desktop_e2e_login_test()
        {
            var appiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();

            appiumOptions.AddAdditionalCapability("app", @"C:\Users\9i9i\source\repos\MailSystemDesktopApp\MailSystemDesktopApp\bin\Debug\net5.0-windows\MailSystemDesktopApp.exe");
            var applicationSession = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions);

            applicationSession.FindElementByName("loginTextBox").SendKeys("admin");
            applicationSession.FindElementByName("passwordTextBox").SendKeys("admin");
            //applicationSession.FindElementByClassName("Button").Click();
            string            current   = applicationSession.CurrentWindowHandle;
            PopupWindowFinder finder    = new PopupWindowFinder(applicationSession);
            string            newHandle = finder.Click(applicationSession.FindElementByClassName("Button"));

            applicationSession.SwitchTo().Window(newHandle);
            applicationSession.FindElementByName("titleTextBox").SendKeys("test");
            var testText = applicationSession.FindElementByName("titleTextBox").Text;

            Assert.IsNotNull(testText);
        }
        public SampleAppSession(TestContext context, int itemCount)
        {
            // Launch Calculator application if it is not yet launched
            if (Session == null)
            {
                string workingDir    = AssemblyDirectory.Replace("ListviewClickHeaderIssue.Tests", "ListviewClickHeaderIssue.SampleApp");
                var    appiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();
                appiumOptions.AddAdditionalCapability("app", $@"{workingDir}\ListviewClickHeaderIssue.SampleApp.exe");
                appiumOptions.AddAdditionalCapability("appArguments", itemCount);
                appiumOptions.AddAdditionalCapability("appWorkingDir", workingDir);

                context.WriteLine($"Setting up options {appiumOptions.ToString()}");

                Session = new WindowsDriver <WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions);
                Assert.IsNotNull(Session);

                // Set implicit timeout to 1.5 seconds to make element search to retry every 500 ms for at most three times
                Session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
            }
        }
Beispiel #7
0
        private WindowsDriver <WindowsElement> GetAppWindowSession(string windowName)
        {
            var appiumOptionsDesktop = new OpenQA.Selenium.Appium.AppiumOptions();

            appiumOptionsDesktop.AddAdditionalCapability("app", "Root");
            var appSesionDesktop = new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptionsDesktop);

            appSesionDesktop.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            var appWindow = appSesionDesktop.FindElementByAccessibilityId(windowName);
            var appTopLevelWindowHandle = appWindow.GetAttribute("NativeWindowHandle");

            appTopLevelWindowHandle = (int.Parse(appTopLevelWindowHandle)).ToString("x");

            var appiumOptionsMainWindow = new OpenQA.Selenium.Appium.AppiumOptions();

            appiumOptionsMainWindow.AddAdditionalCapability("appTopLevelWindow", appTopLevelWindowHandle);
            appiumOptionsMainWindow.AddAdditionalCapability("appWorkingDir", @"D:\Safe-Cloud-File\DesktopApp-Example\bin\Debug\");
            var appSesionMainWindow =
                new WindowsDriver <WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptionsMainWindow);

            appSesionMainWindow.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            return(appSesionMainWindow);
        }
Beispiel #8
0
        public void TestMethod1()
        {
            System.Diagnostics.Debug.WriteLine($"Specifying the text that will be returned by the PingServiceMock to validate that the WpfClient calls this Mock and not another service.");
            PingServiceMock.PingReturn = "Pong From Mock";

            System.Diagnostics.Debug.WriteLine($"TestMethod1: Setting up Appium");
            var options     = new OpenQA.Selenium.Appium.AppiumOptions();
            var exeLocation = System.IO.Path.GetFullPath(@"..\..\..\..\WpfApp1\bin\Debug\netcoreapp3.0\WpfApp1.exe");

            options.AddAdditionalCapability("app", exeLocation);

            var wpfSession = new OpenQA.Selenium.Appium.Windows.WindowsDriver <OpenQA.Selenium.Appium.Windows.WindowsElement>(
                new System.Uri("http://127.0.0.1:4723"),
                options,
                new System.TimeSpan(1, 0, 0));

            var pingButton = wpfSession.FindElementByAccessibilityId("PingButton");

            pingButton.Click();

            var pingLabel = wpfSession.FindElementByAccessibilityId("PingLabel");

            Assert.AreEqual("Pong From Mock", pingLabel.Text);
        }