Example #1
0
        public void Setup()
        {
            var appPath      = @"C:\Users\ffanelli\Desktop\APK\mobile_client.apk";
            var chromeDriver = @"C:\WebDriver\bin\chromedriver.exe";

            //start appium service
            //var builder = new AppiumServiceBuilder();
            //var appiumLocalService = builder.UsingAnyFreePort().Build();
            //appiumLocalService.Start();

            //Capabilities, here we tell the server were we want to run our automation. Which platform, device, application
            //Platform, Device, Application
            //The android options is what replaced the DesiredCapabilities, as this are deprecated
            var driverOption = new AppiumOptions();

            driverOption.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            driverOption.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Android 28");
            driverOption.AddAdditionalCapability(MobileCapabilityType.App, appPath);
            driverOption.AddAdditionalCapability(MobileCapabilityType.Udid, "emulator-5554");
            driverOption.AddAdditionalCapability(MobileCapabilityType.AutomationName, "UiAutomator2");
            driverOption.AddAdditionalCapability("autoGrantPermissions", true);
            driverOption.AddAdditionalCapability("allowSessionOverride", true);
            driverOption.AddAdditionalCapability("appPackage", "com.android.chrome");
            driverOption.AddAdditionalCapability("appActivity", "com.google.android.apps.chrome.Main");

            //the chrome driver is only requirable if we test an hybrid app
            //driverOption.AddAdditionalCapability("chromedriverExecutable", chromeDriver);

            //Here we will do the server initialization, were this android will talk too
            //the uri is the server where we will connect (where the interface is listening )
            Driver = new AndroidDriver <AndroidElement>(new Uri("http://localhost:4723/wd/hub"), driverOption);
            MiscFunctions.SetDriver(Driver);

            //Install MC
            Driver.InstallApp(appPath);

            //Click over the initial setup of chrome
            Activity.ClickById("send_report_checkbox");
            Thread.Sleep(2000);
            Activity.ClickById("terms_accept");
            Thread.Sleep(2000);
            Activity.ClickById("next_button");
            Thread.Sleep(2000);
            Activity.ClickById("negative_button");
            Thread.Sleep(2000);

            Driver.Navigate().GoToUrl("https://www.youtube.com");
            Thread.Sleep(2000);
            Activity.ClickByClassName("widget.Button", "search youtube");
            Thread.Sleep(3000);
            Activity.InputByClassName("widget.EditText", "Rick Astley");
            Thread.Sleep(3000);
            Activity.ClickByClassName("widget.Button", "search youtube");
            Thread.Sleep(3000);
            Activity.ClickByClassName("view.View", "never gonna give you up");
            Thread.Sleep(3000);
            //Driver = new AndroidDriver<AndroidElement>(appiumLocalService.ServiceUrl, driverOption);

            //to automate Native apps whe can use the accesibilityid or class name, like webpages


            //now we need the web view context to automate Hybrid apps
            //var contexts = ((IContextAware) Driver).Contexts;
            //string webviewContext = null;
            //for (var i = 0; i < contexts.Count; i++)
            //{
            //    Console.WriteLine(contexts[i]);
            //    if (contexts[i].Contains("WEBVIEW"))
            //    {
            //        webviewContext = contexts[i];
            //        break;
            //    }
            //}

            //((IContextAware) Driver).Context = webviewContext;
        }
 public BasePage(AndroidDriver <AndroidElement> androidDriver)
 {
     AndroidDriver = androidDriver;
 }
 public void closeFacebookPopup(AndroidDriver <AndroidElement> driver)
 {
     PageFactory.InitElements(this, new RetryingElementLocator(driver, TimeSpan.FromSeconds(10)));
     facebookPopup.Click();
 }
 public ForgotPasswordPage(AndroidDriver <IWebElement> _driver)
 {
     PageFactory.InitElements(_driver, this);
 }
Example #5
0
 public AuthUtils(AndroidDriver <IWebElement> driver) : base(driver)
 {
 }
 public static string GetBatteryStatus(this AndroidDriver <AndroidElement> androidDriver)
 {
     return(ExecuteShellAdbCommand(androidDriver, "adb shell dumpsys battery"));;
 }
Example #7
0
 public SplashPage(AndroidDriver <AndroidElement> AndroidDriver)
 {
     PageFactory.InitElements(AndroidDriver, this);
     _androidDriver = AndroidDriver;
 }
Example #8
0
 public LoginScreen(AndroidDriver <AndroidElement> driver) : base(driver)
 {
 }
Example #9
0
 public LoginPage(IWebDriver driver)
 {
     this.driver = (AndroidDriver <AndroidElement>)driver;
 }
Example #10
0
        protected override void Execute(NativeActivityContext context)
        {
            // Gather fields
            string apkPath          = ApkPath.Get(context);
            string deviceName       = DeviceName.Get(context);
            string version          = AndroidVersion.Get(context);
            string package          = AppPackage.Get(context);
            string activity         = AppActivity.Get(context);
            string locale           = Locale.Get(context) ?? "US";
            string language         = Language.Get(context) ?? "en";
            int    waitTime         = WaitTime.Get(context);
            string screenshotPath   = ScreenshotPath.Get(context) ?? "";
            string chromedriverPath = ChromedriverPath.Get(context) ?? "";

            // Initialize Driver and Appium Server
            AndroidDriver <AndroidElement> driver;
            AppiumLocalService             server;

            // Start Appium Server on any open port
            server = new AppiumServiceBuilder().UsingAnyFreePort().Build();
            server.Start();

            // Set additional capabilities
            var options = new AppiumOptions();

            //Device capabilities
            options.AddAdditionalCapability(MobileCapabilityType.DeviceName, deviceName);
            options.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, version);
            options.AddAdditionalCapability(MobileCapabilityType.Locale, locale);
            options.AddAdditionalCapability(MobileCapabilityType.Language, language);
            // Use UIAutomator2 for better performance
            options.AddAdditionalCapability(MobileCapabilityType.AutomationName, AutomationName.AndroidUIAutomator2);
            // Launch App or Browser depending on user input
            switch (LaunchType)
            {
            case LaunchType.App:
                // App capabilities
                if (!String.IsNullOrEmpty(apkPath))
                {
                    options.AddAdditionalCapability(MobileCapabilityType.App, apkPath);
                }
                options.AddAdditionalCapability(AndroidMobileCapabilityType.AppPackage, package);
                options.AddAdditionalCapability(AndroidMobileCapabilityType.AppActivity, activity);
                break;

            case LaunchType.Browser:
                // Browser capabilities
                switch (BrowserType)
                {
                case BrowserType.Chrome:
                    options.AddAdditionalCapability(MobileCapabilityType.BrowserName, MobileBrowserType.Chrome);
                    if (!String.IsNullOrEmpty(chromedriverPath))
                    {
                        options.AddAdditionalCapability(AndroidMobileCapabilityType.ChromedriverExecutable, chromedriverPath);
                    }
                    break;

                default:
                    throw new ArgumentNullException("Missing Argument: BrowserType.");
                }
                break;

            default:
                throw new ArgumentNullException("Missing Argument: LaunchType.");
            }
            // Default Screenshot Path
            options.AddAdditionalCapability(AndroidMobileCapabilityType.AndroidScreenshotPath, screenshotPath);

            driver = new AndroidDriver <AndroidElement>(server, options);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(waitTime);

            // Export driver
            Driver.Set(context, driver);

            // Schedule Activities
            if (Body != null)
            {
                context.ScheduleAction <AndroidDriver <AndroidElement> >(Body, driver, OnCompleted, OnFaulted);
            }
        }
 public AndroidFileSystemService(AndroidDriver <AndroidElement> wrappedDriver)
     : base(wrappedDriver)
 {
 }
Example #12
0
 public static void Init(IObjectContainer objectContainer)
 {
     _driver = AndroidDriver.Init();
     objectContainer.RegisterInstanceAs(_driver);
 }
 public static void Start(string browserName = "")
 {
     Driver = new AndroidDriver <AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"),
                                                 GetDesiredCapabilities(browserName), TimeSpan.FromSeconds(180));
     Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
 }
 public EvernoteAddNoteTypeList(AndroidDriver <AndroidElement> driver)
 {
     PageFactory.InitElements(driver, this);
     this._driver = driver;
 }
 public static void ChangeBatteryLevel(this AndroidDriver <AndroidElement> androidDriver, int level)
 {
     ExecuteShellAdbCommand(androidDriver, $"dumpsys battery set level {level}");
 }
Example #16
0
 public SignUpWithEmailPage(AndroidDriver <AndroidElement> driver)
 {
     _driver = driver;
 }
 public static void ResetBattery(this AndroidDriver <AndroidElement> androidDriver)
 {
     ExecuteShellAdbCommand(androidDriver, "adb shell dumpsys battery reset");
 }
Example #18
0
 public HomePage(AndroidDriver <IWebElement> driver)
 {
     this.driver = driver;
     PageFactory.InitElements(driver, this);
 }
 private static string ExecuteShellAdbCommand(AndroidDriver <AndroidElement> androidDriver, string command, params string[] args)
 {
     return(androidDriver.ExecuteScript("mobile: shell", new AdbCommand(command, args).ToString()).ToString());
 }
 public MobileWrapper(AndroidDriver <IWebElement> driver)
 {
     _appiumDriver = driver;
 }
Example #21
0
 public AppLoginPage(AndroidDriver <AndroidElement> driver)
 {
     driver = driver;
     PageFactory.InitElements(driver, this);
 }
 /// <summary>
 /// 实例化屏幕组件实现类
 /// </summary>
 public AndroidEntityView(AndroidDriver <AndroidElement> androidDriver)
 {
     AndroidDriver    = androidDriver;
     DeviceWindowSize = AndroidDriver.Manage().Window.Size;
 }
 public ContactAppPage(AndroidDriver <AndroidElement> driver)
     : base(driver)
 {
 }
Example #24
0
 public LoginViewPageObject(AndroidDriver <AndroidElement> androidDriver) : base(androidDriver)
 {
 }
Example #25
0
 public void Initialize()
 {
     driver = new AndroidDriver <IWebElement>(Configs.kobitonServerUrl(), Configs.desiredCapabilitiesAndroidApp(), TimeSpan.FromSeconds(Configs.SESSION_TIMEOUT));
     driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(120));
 }
 public override IEnumerable <AndroidElement> FindAllElements(AndroidDriver <AndroidElement> searchContext) => searchContext.FindElementsByAndroidUIAutomator(Value);
Example #27
0
 public override IEnumerable <AndroidElement> FindAllElements(AndroidDriver <AndroidElement> searchContext)
 {
     return(searchContext.FindElementsByAndroidUIAutomator(_locatorValue));
 }
 public static string GetLogs(this AndroidDriver <AndroidElement> androidDriver)
 {
     return(ExecuteShellAdbCommand(androidDriver, "logcat"));;
 }
Example #29
0
 public override AndroidElement FindElement(AndroidDriver <AndroidElement> searchContext)
 {
     return(searchContext.FindElementByAndroidUIAutomator(_locatorValue));
 }
 public AppiumUtilities(AppiumLocalService appiumLocalService, AndroidDriver <AndroidElement> androidDriver = null, IOSDriver <IOSElement> iOSDriver = null)
 {
     _appiumLocalService = appiumLocalService;
     _androidDriver      = androidDriver;
     _iosDriver          = iOSDriver;
 }