Xamarin UI测试Android日期选择器(暂停)

时间:2015-08-06 16:55:12

标签: xamarin android-5.0-lollipop android-5.1.1-lollipop

我正在使用Xamarin UI Test(1.0.0)。我正在尝试编写一个更新所选日期的扩展方法。 这是我到目前为止所写的内容。它适用于iOS和Android 4.x.它不适用于Android 5.x。

   public static void EnterDate(this IApp app, string datePickerStyleId, DateTime date)
    {
        var array = app.Query(datePickerStyleId);
        if (array.Length == 0)
            return;
        foreach (var picker in array)
        {
            var newMonth = date.ToString("MMM");
            var newDay = date.Day.ToString();
            var newYear = date.Year.ToString();
            if (app.IsAndroid())
            {
                app.Tap(picker.Label);
                //if device OS > 5 try scrolll up
                app.Repl();
                app.Screenshot("Date Picker");
                app.Tap("month");
                app.EnterText(newMonth);
                app.PressEnter();
                app.Tap("day");
                app.EnterText(newDay);
                app.PressEnter();
                app.Tap("year");
                app.EnterText(newYear);
                app.PressEnter();
                app.ClickDone();
                app.Screenshot("Page After Changing Date");
                app.ClickButton("Ok");
            }
            else if (app.IsIOS())
            {
                app.Tap(picker.Id);
                app.Screenshot("Date Picker");
                var currentDate = picker.Text;
                var split = currentDate.Split(' ');
                var currentMonth = split[0];
                var currentDay = split[1].Remove(split[1].Length - 1);
                var currentYear = split[2];
                if (!newMonth.Equals(currentMonth))
                {
                    app.Tap(newMonth);
                }
                if (!newDay.Equals(currentDay))
                {
                    app.Tap(newDay);
                }
                if (!newYear.Equals(currentYear))
                {
                    app.Tap(newYear);
                }
                app.ClickButton("Done");
            }
        }
    }

我遇到的问题是我无法弄清楚如何选择某个日期。 App.ScrollUp()/。ScrollDown()可以导航到不同的月份。虽然,我还没有找到确定当前月份然后选择一天。以下是Repl()工具的树命令的输出。

  
    
      

tree [[object CalabashRootView]> ...> FrameLayout] [FrameLayout] id:“content”[LinearLayout] id:“parentPanel”[FrameLayout] id:“customPanel”[FrameLayout] id:“custom”[DatePicker> LinearLayout] id:“datePicker”[LinearLayout] id:“day_picker_selector_layout”
                    [TextView] id:“date_picker_header”text:“Thursday”                     [LinearLayout] id:“date_picker_month_day_year_layout”                       [LinearLayout] id:“date_picker_month_and_day_layout”,标签:“8月6日”                         [TextView] id:“date_picker_month”text:“AUG”                         [TextView] id:“date_picker_day”text:“6”                       [TextView] id:“date_picker_year”text:“2015”                   [AccessibleDateAnimator> ...> SimpleMonthView] id:“animator”,标签:“月份网格天数:8月6日”             [LinearLayout] id:“buttonPanel”               [按钮] id:“button2”文字:“取消”               [按钮] id:“button1”文字:“确定”

    
  

是否有人知道或有方法选择适用于iOS和Android(4.x和5.x)的Xamarin UI测试日期?

0 个答案:

没有答案