public void TestUCBrowser()
        {
            string appPath = @"D:\git-zjs\Appium-Test-ios-android\AppiumDriverDemo\Apps\UCBrowser_V9.8.0.435_Android_pf145_(Build14052717).apk";

            DesiredCapabilities cap = new DesiredCapabilities();
            //cap.SetCapability("appium-version", "1.0");
            cap.SetCapability(CapabilityType.BrowserName, "");
            cap.SetCapability("platformName", "Android");
            cap.SetCapability("browserName", "UC Browser");
            cap.SetCapability("udid", "EAZSRK6HIJHEAYSK");  //三星手机 //4d00627749d2a037  //三星手机2  1844d244  红米手机 //EAZSRK6HIJHEAYSK   小米3 //bba1bd7
            cap.SetCapability("app", appPath);

            //UC Browser设置
            cap.SetCapability("appPackage", "com.UCMobile");
            cap.SetCapability("appActivity", "com.uc.browser.InnerUCMobile");

            driver = new AppiumDriver(new Uri("http://localhost:4723/wd/hub"), cap);
            Thread.Sleep(2000);
            IList<IWebElement> ltEle = driver.FindElements(By.ClassName("android.view.View"));
            ltEle[ltEle.Count - 1].Click();
            Thread.Sleep(2000);

            //IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            //Hashtable keycodes = new Hashtable();

            //keycodes.Add("KEYCODE_C", "31");
            //js.ExecuteScript("mobile:keyevent", keycodes);

            //Thread.Sleep(5000);

            CommonFunction comFun = new CommonFunction();
            comFun.ITakesScreenshots(driver);
            Thread.Sleep(2000);
            driver.Quit();
        }
        public void ByIosUIAutomationTestCase()
        {
            server.respondTo("POST", "/element", new Dictionary <string, object>  {
                { "ELEMENT", '5' }
            });
            driver.FindElement(new ByIosUIAutomation(".elements()"));
            (new ByIosUIAutomation(".elements()")).FindElement(driver);
            server.clear();
            List <object> results = new List <object>();

            results.Add(new Dictionary <string, object> {
                { "ELEMENT", "4" }
            });
            server.respondTo("POST", "/elements", results);
            driver.FindElements(new ByIosUIAutomation(".elements()"));
            (new ByIosUIAutomation(".elements()")).FindElements(driver);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 跑真机 
        /// </summary>
        public void TestAPPDevices()
        {
            string appPath = @"D:\git-zjs\Appium-Test-ios-android\AppiumDriverDemo\Apps\ctrip_9013.apk";
            //string appPath = @"F:\Test-zj-2014\Appium-Test-ios-android\AppiumDriverDemo\Apps\ctrip_9013.apk";
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.SetCapability("deviceName", "HC44DWM01308");    // 真机
            cap.SetCapability("platformName", "Android");    // 真机
            cap.SetCapability("udid", "HC44DWM01308");    // 真机
            cap.SetCapability("app", appPath);
            cap.SetCapability("appPackage", "ctrip.android.view");
            cap.SetCapability("appActivity", "ctrip.android.view.home.CtripSplashActivity");
            var driver = new AppiumDriver(new Uri("http://localhost:4723/wd/hub"), cap);

            Thread.Sleep(15000);
            try
            {
                var isEXIT = driver.FindElement(By.Name("以后再说"));
                if (isEXIT != null)
                {
                    driver.FindElement(By.Name("以后再说")).Click();

                }

            }
            catch (Exception ex)
            {

            }

            Thread.Sleep(2000);

            #region  通过js执行滑动屏幕的功能
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            Hashtable swipObj = new Hashtable();
            swipObj.Add("startX", 300.0);
            swipObj.Add("startY", 300.0);
            swipObj.Add("endX", 20.0);
            swipObj.Add("endY", 20.0);
            swipObj.Add("duration", 0.5);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(2000);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(2000);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(2000);
            js.ExecuteScript("mobile: swipe", swipObj);
            #endregion
            Thread.Sleep(3000);

            //方式1  定位
            //driver.FindElement(By.Name("机票")).Click();

            //方式2  定位
            //driver.FindElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.TextView\").text(\"机票\")").Click();
            //Thread.Sleep(7000);

            //下单---针对门票

            //登陆--我的携程
            driver.FindElement(By.Name("我的携程")).Click();
            Thread.Sleep(3000);
            driver.FindElement(By.Name("点击登录")).Click();
            Thread.Sleep(3000);

            driver.FindElement(By.Name("携程用户名/绑定手机/邮箱/卡号")).SendKeys("test111111");
            Thread.Sleep(3000);

            var editTexts = driver.FindElements(By.ClassName("android.widget.EditText"));
            Thread.Sleep(3000);
            editTexts[editTexts.Count - 1].SendKeys("123456789");
            Thread.Sleep(3000);

            driver.FindElements(By.ClassName("android.widget.Button"))[0].Click();
            Thread.Sleep(9000);

            //我的携程
            driver.FindElement(By.Name("首页")).Click();
            Thread.Sleep(3000);

            driver.FindElement(By.Name("度假")).Click();
            Thread.Sleep(2000);

            driver.FindElement(By.Id("ctrip.android.view:id/inquire_ticket")).Click();
            Thread.Sleep(10000);

            //搜索框
            //driver.FindElementByAccessibilityId("景点名称/城市/游玩主题").Click(); //该方法成功了
            //Thread.Sleep(10000);
            //driver.FindElement(By.ClassName("android.widget.EditText")).SendKeys("上海");
            //Thread.Sleep(5000);
            //driver.FindElementByAccessibilityId("搜索").Click();
            //Thread.Sleep(5000);

            //其他定位方式 未成功
            //driver.FindElementByAndroidUIAutomator("new UiSelector().className(\"android.widget.TextView\").text(\"机票\")").Click();
            //driver.FindElementByAndroidUIAutomator("new UiSelector().Desctiption(\"景点名称/城市/游玩主题\")").Click();
            //driver.FindElements(By.ClassName("android.widget.RelativeLayout"))[1].FindElements(By.ClassName("android.view.View"))[8].Click();
            //driver.FindElements(By.ClassName("android.widget.RelativeLayout"))[1].Click();

            //Thread.Sleep(5000);
            //driver.FindElement(By.ClassName("android.widget.EditText")).SendKeys("上海");
            //Thread.Sleep(5000);

            #region  其余后面的步骤
            driver.FindElementByAccessibilityId("上海").Click();
            Thread.Sleep(5000);

            //上海科技馆 Heading
            driver.FindElementByAccessibilityId("上海科技馆 Heading").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("预订").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("请选择游玩日期").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("17").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("接收确认短信").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("测试").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("下一步").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("常用卡支付").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("宁波银行-信用卡").Click();
            Thread.Sleep(5000);

            driver.FindElements(By.ClassName("android.widget.EditText"))[0].SendKeys("0003");
            Thread.Sleep(5000);

            driver.FindElements(By.ClassName("android.widget.Button"))[0].Click();
            Thread.Sleep(5000);

            //返回
            driver.FindElements(By.ClassName("android.view.View"))[0].Click();
            Thread.Sleep(5000);

            //返回我的携程退票操作
            driver.FindElement(By.Name("我的携程")).Click();
            Thread.Sleep(5000);

            driver.FindElement(By.Name("全部订单")).Click();
            Thread.Sleep(5000);

            driver.FindElement(By.Name("景点门票订单")).Click();
            Thread.Sleep(15000);

            driver.FindElementByAccessibilityId("申请取消").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("申请取消").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("确认").Click();
            Thread.Sleep(9000);
            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 跑模拟器 
        /// </summary>
        public static void TestAPPEmulator()
        {
            try
            {
            AppiumDriver driver;
            string appPath = @"D:\git-zjs\Appium-Test-ios-android\AppiumDriverDemo\Apps\ctrip_9014.apk";
            //DesiredCapabilities cap = new DesiredCapabilities();
            ////cap.SetCapability("udid", "emulator-5554");  //虚拟机 43200000

            //cap.SetCapability("udid", "4d00627749d2a037");
            //cap.SetCapability("app", appPath);
            //driver = new AppiumDriver(new Uri("http://localhost:4729/wd/hub"), cap);

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.SetCapability("deviceName", "BH9007EU15");    // 真机
            cap.SetCapability("platformName", "Android");    // 真机
            cap.SetCapability("udid", "BH9007EU15");    // 真机
            cap.SetCapability("app", appPath);
            driver = new AppiumDriver(new Uri("http://localhost:4799/wd/hub"), cap);

            Thread.Sleep(35000);

            #region  通过js执行滑动屏幕的功能
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            Hashtable swipObj = new Hashtable();
            swipObj.Add("startX", 300.0);
            swipObj.Add("startY", 300.0);
            swipObj.Add("endX", 20.0);
            swipObj.Add("endY", 20.0);
            swipObj.Add("duration", 0.5);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(3000);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(3000);
            js.ExecuteScript("mobile: swipe", swipObj);
            Thread.Sleep(3000);
            js.ExecuteScript("mobile: swipe", swipObj);
            #endregion
            Thread.Sleep(5000);

            //登陆--我的携程
            driver.FindElement(By.Name("我的携程")).Click();
            Thread.Sleep(3000);
            driver.FindElement(By.Name("点击登录")).Click();
            Thread.Sleep(3000);

            //driver.FindElement(By.Name("携程用户名/绑定手机/邮箱/卡号")).Clear();
            //Thread.Sleep(3000);

            driver.FindElement(By.Name("携程用户名/绑定手机/邮箱/卡号")).SendKeys("test111111");
            Thread.Sleep(3000);

            var editTexts = driver.FindElements(By.ClassName("android.widget.EditText"));
            Thread.Sleep(3000);
            editTexts[editTexts.Count - 1].SendKeys("123456789");
            Thread.Sleep(3000);

            driver.FindElements(By.ClassName("android.widget.Button"))[0].Click();
            Thread.Sleep(9000);

            driver.FindElement(By.Name("首页")).Click();
            Thread.Sleep(9000);

            driver.FindElement(By.Name("门票")).Click();
            Thread.Sleep(17000);

            //选择上海 注意 这里的XPath不是从0开始数的 从1开始数
            driver.FindElement(By.XPath(".//android.widget.ListView[2]/android.view.View[1]")).Click();

            Thread.Sleep(5000);

            //上海科技馆 Heading
            driver.FindElementByAccessibilityId("上海科技馆 Heading").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("预订").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("请选择游玩日期").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("31").Click();
            Thread.Sleep(9000);

            //driver.FindElementByAccessibilityId("接收确认短信").Click();
            //Thread.Sleep(9000);

            //driver.FindElementByAccessibilityId("测试一").Click();
            //Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("出行人").SendKeys("");
            Thread.Sleep(5000);

            //driver.FindElementByAccessibilityId("手机").SendKeys("");
            //Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("测试").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("下一步").Click();
            Thread.Sleep(9000);

            driver.FindElementByAccessibilityId("常用卡支付").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("宁波银行 - 信用卡").Click();
            Thread.Sleep(5000);

            //driver.FindElements(By.ClassName("android.widget.EditText"))[0].SendKeys("0003");
            //Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("月份/年份").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("确定").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("支付").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("支付方式在线支付").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("申请取消").Click();
            Thread.Sleep(5000);

            driver.FindElementByAccessibilityId("确认").Click();
            Thread.Sleep(9000);

            driver.Quit();

            }
               catch (Exception ex)
               {
                   Console.WriteLine("4d00627749d2a037" + ex.ToString());
                   //driver.Quit();

               }
        }