C#与Ranorex自动化公用方法

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

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

一、打开浏览器;或者appweb

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); }

 

 

二、删除之前的值,输入一个值;c#

//输入框中内容先删除后填写
 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; // }
 }

 

三、 下拉列表框中选择或者输入一个值浏览器

//输入内容
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; } } } }

 

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

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

五、点击一个按钮spa

adapter1.Click();code

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

//等待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; } } }

 

七、经过xpath来找到某个控件(或判断某个控件是否存在)htm

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);

 

八、经过坐标来点击控件

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item '导航按钮' at 35;131.", repo.导航按钮Info, new RecordItemIndex(6)); repo.导航按钮.Click("35;131"); Delay.Milliseconds(200);
相关文章
相关标签/搜索