• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#与Ranorex自动化公用方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
原创 - 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);

 

 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap