コード例 #1
0
        /// <summary>
        /// Perform Operation on Browser window/tabs.
        /// Sample Usage:
        /// <para>BrowserOperation(TabOperation.SwitchTab, () => WebDriver.Instance.Url.Contains("WebCase"));</para>
        /// <para>BrowserOperation(TabOperation.CloseTab, () => WebDriver.Instance.Title.Contains("Case Administration"));</para>
        /// <para>BrowserOperation(TabOperation.CloseMultipleTabsExceptThis, () => !WebDriver.Instance.Url.Contains("WebCase"));//closes
        /// all tabs except the one containing above url</para>
        /// </summary>
        /// <param name="operation">Operation to perform <see cref="TabOperation"/></param>
        /// <param name="searchCriteria">Condition searchText need to satisfy</param>
        /// <returns> boolean flag indicating whether operation was succesfully performed or not.</returns>
        public static bool Operation(TabOperation operation, Func <bool> searchCriteria)
        {
            bool isOperationSuccessful = false;

            switch (operation)
            {
            case TabOperation.SwitchTab:
                isOperationSuccessful = SwitchingBrowserTab(searchCriteria);
                break;

            case TabOperation.CloseTab:
                isOperationSuccessful = CloseTab(searchCriteria);
                break;

            case TabOperation.CloseMultipleTabsExceptThis:
                isOperationSuccessful = RepeatedOperation(() => CloseTab(searchCriteria),
                                                          () => MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count > 1);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(operation), operation, null);
            }

            return(isOperationSuccessful);
        }
コード例 #2
0
        /// <summary>
        /// Switches to the expected browser tab based on condition and search text provided.
        /// </summary>
        /// <param name="searchText">text to search for</param>
        /// <param name="condition">condition to be satisfied for the </param>
        /// <returns></returns>
        private static bool SwitchingBrowserTab(Func <bool> condition)
        {
            bool isSwitchTabSuccessful = false;
            int  tabCount = MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count;

            if (condition())
            {
                TestContext.WriteLine("No need to switch tabs, already on the expected tab");
                isSwitchTabSuccessful = true;
                return(isSwitchTabSuccessful);
            }

            for (int i = 0; i < tabCount; i++)
            {
                MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[i]);
                Wait.Seconds(0.25);
                if (condition())
                {
                    isSwitchTabSuccessful = true;
                    return(isSwitchTabSuccessful);
                }
            }
            if (!condition())
            {
                TestContext.WriteLine($"Cannot switch to Browser tab with [{nameof(condition)}] criteria!");
            }

            return(isSwitchTabSuccessful);
        }
コード例 #3
0
        public static void SetupDriver(MobileDriver driverType, bool installApp = false)
        {
            string ErrMsg;

            switch (driverType)
            {
            case MobileDriver.Android:
                SetupOptions();
                MiscFunctions.SetDriver(Driver);

                //Install MC apk
                if (installApp)
                {
                    Driver.InstallApp(GlobalVar.ApkPath);
                }
                break;

            case MobileDriver.Ios:
                break;

            case MobileDriver.Web:
                //killProcess(out ErrMsg, "chrome");
                //killProcess(out ErrMsg, "chromedriver");
                break;
            }
        }
コード例 #4
0
        public void CreateAndroidDriverInGridWithWebAppByDefaultPasses()
        {
            System.Console.WriteLine($"Thread # [{System.Threading.Thread.CurrentThread.ManagedThreadId}]");
            //Check if this is true for IOSdriver
            AndroidDriver <AppiumWebElement> driver = MobileDriver.Get <AndroidDriver <AppiumWebElement> >();
            // TestLogs.WriteDeviceLogs();
            ServerCommandExecutor executor = new ServerCommandExecutor(this.GetParameters().ServerUri, driver.SessionId);

            Console.WriteLine($"Current device orientation is:{driver.Orientation}");
            executor.Execute("setOrientation", new Dictionary <string, object> {
                { "orientation", "LANDSCAPE" }
            });
            Console.WriteLine($"New device orientation is: {driver.Orientation}");
            TestContext.WriteLine($"Web app SessionId is:[{driver.SessionId}]");
            Assert.NotNull(driver, $"driver cannot be null");
            /*System.Console.WriteLine($"Server running test [{driver.PlatformName}]");*/
            driver.Navigate().GoToUrl("http://google.com");
            System.Console.WriteLine($"Curretn activity:{driver.CurrentActivity}");

            Wait.ForPageToLoad();
            AppiumWebElement searchTextControl = driver.FindElement(By.CssSelector("div.SDkEP input.gLFyf"), 10);

            searchTextControl.Click();
            searchTextControl.SendKeys("Hello there@@");
            Wait.Seconds(3);
            Assert.AreEqual(driver.Contexts.Count, 2, "Multiple Contexts");
            Assert.AreEqual(driver.Context.ToString(), "CHROMIUM", "Expected Chromium context");
            OpenQA.Selenium.Remote.Response result1 = executor.Execute("getAvailableLogTypes");
            Console.WriteLine($"Supported Log Types:\n {result1.ToJson()}");
        }
コード例 #5
0
ファイル: GridProvider.cs プロジェクト: JP-3/Appium
        /// <summary>
        /// Creation of the drivers for the tests to use
        /// </summary>
        /// <param name="driverCount"> number of appium drivers to spin up for the test</param>
        /// <param name="methodInfo">Method Information</param>
        /// <returns>Mobile Driver List</returns>
        public List <MobileDriver> CreateDrivers(int driverCount, MethodInfo methodInfo)
        {
            MobileDrivers = new List <MobileDriver>();

            MobileDriver mobileDriver = new MobileDriver();

            mobileDriver.CreateAppiumDriver(MobileDriverFactory.Que.CheckoutDevice(methodInfo.Name));
            MobileDrivers.Add(mobileDriver);

            return(MobileDrivers);
        }
コード例 #6
0
        /// <summary>
        /// Closes all tabs but one
        /// </summary>
        public static void CloseAllButOne()
        {
            MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[0]);
            while (MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count > 1)
            {
                MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[1]);
                MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().CurrentWindowHandle)
                .Close();
            }

            MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[0]);
        }
コード例 #7
0
        /// <summary>
        /// Closes a browser tab
        /// </summary>
        /// <param name="searchText">text to search for in the interested tab</param>
        /// <param name="condition">condition to find the searchText in the interested tab</param>
        /// <returns></returns>
        private static bool CloseTab(Func <bool> condition)
        {
            int  startCount, count = 0;
            bool isOperationSuccessful = false;

            startCount = MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count;
            if (startCount <= 1)
            {
                TestContext.WriteLine($"Cannot perform operation as Browser Tab count is [{startCount}]." +
                                      $"This would immediately close the browser.");
                return(isOperationSuccessful);
            }

            int index = 0;

            do
            {
                if (count > 5)
                {
                    TestContext.WriteLine($"Cannot close tab, too many open [>5].");
                    break;
                }

                if (index < MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count)
                {
                    MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo()
                    .Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[index]);
                }

                if (condition())
                {
                    MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo().Window(MobileDriver.Get <AppiumDriver <IWebElement> >().CurrentWindowHandle).Close();
                    isOperationSuccessful = true;
                    int currentCount = MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count;
                    //Switch to first tab coz we don't know where we need to be anymore.
                    MobileDriver.Get <AppiumDriver <IWebElement> >().SwitchTo()
                    .Window(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles[MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count - 1]);
                    Wait.Seconds(0.25);
                    break;
                }
                count++;
                index++;
            } while(MobileDriver.Get <AppiumDriver <IWebElement> >().WindowHandles.Count > 1);

            return(isOperationSuccessful);
        }
コード例 #8
0
ファイル: CheckBox.cs プロジェクト: fernandofanelli/Appium
 public static void ClickByDevice(string element, int position, MobileDriver deviceType = MobileDriver.Android)
 {
     try
     {
         var elements = GlobalVar.AndroidDriver.FindElementsById(element);
         switch (deviceType)
         {
         case MobileDriver.Android:
             elements[position].Click();
             break;
         }
     }
     catch (Exception ex)
     {
         Assert.Fail("ClickCheckBoxByDevice threw an exception: " + ex.Message);
     }
 }
コード例 #9
0
        public void MobileStartup()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability(MobileCapabilityType.PlatformName, "Android");
            capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "9.0");
            capabilities.SetCapability(MobileCapabilityType.DeviceName, "emulator-5554");
            capabilities.SetCapability(MobileCapabilityType.Udid, "52004a18537135e3");

            //capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2");
            //capabilities.SetCapability(MobileCapabilityType.BrowserName, "chrome");
            capabilities.SetCapability(MobileCapabilityType.App, "C:\\Users\\balla.niang\\Downloads\\WikipediaSample.apk");
            capabilities.SetCapability("appActivity", "org.wikipedia.page.PageActivity");
            capabilities.SetCapability("appPackage", "org.wikipedia.alpha");



            MobileDriver driver = new MobileDriver("http://192.168.100.64:4723/wd/hub", capabilities);

            driver.Quit();
        }
コード例 #10
0
        public void Mobiletest()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();

            capabilities.SetCapability(MobileCapabilityType.PlatformName, "Android");
            capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "10");
            capabilities.SetCapability(MobileCapabilityType.DeviceName, "8B3Y0TC63");
            //capabilities.SetCapability(MobileCapabilityType.Udid, "52004a18537135e3");

            //capabilities.SetCapability(MobileCapabilityType.AutomationName, "UIAutomator2");
            //capabilities.SetCapability(MobileCapabilityType.BrowserName, "chrome");
            //capabilities.SetCapability(MobileCapabilityType.App, "C:\apps\AA.apk");
            capabilities.SetCapability("appActivity", "com.carebook.android.module.entrypoint.EntryPointActivity");
            capabilities.SetCapability("appPackage", "app.letsbewell.android.qa");



            MobileDriver driver = new MobileDriver("http://192.168.100.64:4723/wd/hub", capabilities);

            driver.Quit();
        }
コード例 #11
0
ファイル: KobitonTestProvider.cs プロジェクト: JP-3/Appium
        /// <summary>
        /// Creates a mobile driver based on device information
        /// </summary>
        /// <returns>The driver.</returns>
        /// <param name="device">Device.</param>
        /// <param name="methodInfo"></param>
        private MobileDriver CreateDriver(Device device, MethodInfo methodInfo)
        {
            var driver = new MobileDriver();

            var capabilities = CreateDesiredCapabilities(device, methodInfo);

            //if (capabilities.GetCapability("platformName").ToString() == "Android")
            //{
            try
            {
                driver.AppiumDriver = AndroidDriver(capabilities);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            //}
            //else
            //{
            //    driver.AppiumDriver = IOSDriver(capabilities);
            //}

            return(driver);
        }
コード例 #12
0
ファイル: DriverSelector.cs プロジェクト: gkohne/Moblie.Core
 public static AndroidDriver <IWebElement> CreateAndriodDriver()
 {
     return(MobileDriver.CreateAndriodDriver(Settings.AndriodVersion));
 }
コード例 #13
0
 public void Setup()
 {
     mobileDriver = new MobileDriver();
 }