zoukankan      html  css  js  c++  java
  • C#与Ranorex自动化公用方法

    原创 - C#与Ranorex自动化公用方法

    利用c#在Ranorex上写自动化已经有很长的一段时间了,总结发现常用的方法不外乎如下几种:

    1、打开浏览器;或者app

    public static void openBrowserMax(){
               Report.Log(ReportLevel.Info, "Website", "Opening web site 'https://www.baidu.com' with browser 'IE' in normal mode.", new RecordItemIndex(0));
               Host.Local.OpenBrowser("https://www.baidu.com", "Chrome", "", true, true, false, false, false);
               Delay.Milliseconds(0);
               }
     

    2、删除以前的值,输入一个值;

     //输入框中内容先删除后填写
     public static void deleteAndInput(Ranorex.Adapter adapter, string item, Ranorex.Core.Repository.RepoItemInfo report)
    {
                      
        Report.Log(ReportLevel.Info, "清空并输入", ""+""+report+""+"处删除原有数据,并输入:【"+item+"】。");
         adapter.Click();
         //while(!adapter.Element.HasFocus)  {adapter.Click("0;0"); adapter.Focus(); };
         Keyboard.Press(System.Windows.Forms.Keys.End | System.Windows.Forms.Keys.Shift, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
         Keyboard.Press(System.Windows.Forms.Keys.Delete, Keyboard.DefaultScanCode, Keyboard.DefaultKeyPressTime, 1, true);
         adapter.PressKeys(item);
         Delay.Milliseconds(500);
                            
    //   if(adapter.Element.GetAttributeValueText("Value")==item || adapter.Element.GetAttributeValueText("Text")==item || adapter.Element.GetAttributeValueText("InnerText")==item)
    //   {
    //    break;
    //    }
                      
    }

    3、 下拉列表框中选择或者输入一个值

    //输入内容
    public static void selectItem(Ranorex.Adapter adapter, string item, Ranorex.Core.Repository.RepoItemInfo report)
     {
          Report.Log(ReportLevel.Info, "选择下拉选项",  ""+""+report+""+"处选择"+""+item+""+"");
          if (!string.IsNullOrEmpty(item)) {
              adapter.Focus();
              adapter.PressKeys(item);//输入数据
                            
              Delay.Duration(500, false);
          }
    }
                    
     //输入某一选项
     public static void selectList(Ranorex.Adapter adapter,string value, int length)
    {             
       //IList<LiTag> li = repo.NewFolder.销售机会新建.ComboboxDropdown.FindDescendants<LiTag>();
    
       //找到控件adapter的LiTag后代
       IList<LiTag> li = adapter.FindDescendants<LiTag>();
       foreach(LiTag l in li)
       {
            string text = l.InnerText;
            if(text.Length>=2)
            {
                Report.Log(ReportLevel.Info,text);
                string text1 = text.Substring(0,length);
                if(value==text1)
                 {
                    l.Click(); //也可以换成l.selected = true; 如果有selected这个属性的话
                    break;
                  }
              }
        }
    }

    4、通过按Down按钮或则Up来再下拉列表框中选择一个值

        Keyboard.Press("{Down 7}{Up 4}{Enter}");

    5、点击一个按钮

    adapter1.Click();

    6、点击按钮直到某个控件出现为止

    //等待30s知道某个控件出现
    public static void waitfor30sReportExist(Ranorex.Adapter adapter1, Ranorex.Core.Repository.RepoItemInfo adapter2Info){
          int count = 0;
          Report.Log(ReportLevel.Info,"双击"+adapter1.ToString()+",等待"+adapter2Info.ToString()+"出现");
          while(!adapter2Info.Exists()){
               adapter1.Click();
               Delay.Milliseconds(5000,false);
               count = count + 1;
                if(count >= 6)
                {
                     Report.Log(ReportLevel.Failure,"在30s内没有找到控件"+adapter2Info.ToString());
                     break;
                 }
                            
           }
    }

    7、通过xpath来找到某个控件(或判断某个控件是否存在)

    Element element = Element.FromPath("/dom[@caption='******' and @page='quotation_search.html']//table[#'resultTable']/tbody/tr");
    
               
    RxPath xpa = new RxPath("/dom[@caption='*****' and @page='quotation_search.html']//table[#'resultTable']/tbody/tr");
    IList<Element> ils= element.Find(xpa);
    Report.Info("ils.count:" + ils.Count);

    8、通过坐标来点击控件

    Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item '导航按钮' at 35;131.", repo.导航按钮Info, new RecordItemIndex(6));
    repo.导航按钮.Click("35;131");
    Delay.Milliseconds(200);
     
  • 相关阅读:
    java-Swatch的坑
    Java基本数据类型
    jQuery属性、事件、链式编程、$冲突
    jQuery页面改变大小事件,滑动页面事件
    JavaScript简介
    CSS页面布局格式
    CSS Float(浮动)
    css定位
    CSS知识点2
    CSS知识点1
  • 原文地址:https://www.cnblogs.com/scarlett-hy/p/10277767.html
Copyright © 2011-2022 走看看