HtmlAutoTestFrameWork

前段時間做的自動化測試的是Silverlight的,框架都已經搭好。突然測試發現這里還有一個要發送郵件的html頁面,并且將另外啟動瀏覽器,于是今天下午把這個html的也寫出來。

用法 :

HtmlAutoTestFrameWork htf = new HtmlAutoTestFrameWork();
htf.BrowserDefaultIE();

?HtmlTextArea heTo2 = htf.ByPropert<HtmlTextArea>("Id:input-to;TagName:TEXTAREA;Class:text");

heTo2.Text = "admin@cnblogs.com";

HtmlButton hbSend = htf.ByPropert<HtmlButton>("Id:btnSend;TagName:INPUT;ControlType:Button");
Mouse.Click(hbSend);

下面是html的一個彈出層,用的jsalert.js .獲取彈出層元素

HtmlDiv htmlDiv = htf.ByPropert<HtmlDiv>("Id:popup_container;Class:ui-draggable");

這是彈出層得一個按鈕

HtmlInputButton hbok = htf.ByPropert<HtmlInputButton>("Id:popup_ok;Type:button");
Mouse.Click(hbok);

?

下面是源碼供參考

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UITesting;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using System.Diagnostics;
using System.Reflection;namespace autoUI
{public class HtmlAutoTestFrameWork{private string m_uri = string.Empty;private BrowserWindow browser;public HtmlDocument htmlDoc;public string Title = string.Empty;public string AbsolutePath = string.Empty;public string ClassName = string.Empty;public string FrameDocument = string.Empty;#region HtmlDocumentpublic void BrowserLaunch(){}public void BrowserLaunch(String Url){m_uri = Url;browser = BrowserWindow.Launch(Url);BuildParams();}private void BuildParams(){browser.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame";htmlDoc = new Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument(browser);if (!string.IsNullOrWhiteSpace(m_uri))htmlDoc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.PageUrl] = m_uri;if (!string.IsNullOrWhiteSpace(Title))htmlDoc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.Title] = Title;if (!string.IsNullOrWhiteSpace(AbsolutePath))htmlDoc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.AbsolutePath] = AbsolutePath;if (!string.IsNullOrWhiteSpace(ClassName))htmlDoc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.ClassName] = ClassName;if (!string.IsNullOrWhiteSpace(FrameDocument))htmlDoc.SearchProperties[Microsoft.VisualStudio.TestTools.UITesting.HtmlControls.HtmlDocument.PropertyNames.FrameDocument] = FrameDocument;}public void BrowserDefaultIE(){browser = BrowserWindow.FromProcess(GetProcess("iexplore"));BuildParams();}public void BrowserFromProcess(Process p){browser = BrowserWindow.FromProcess(p);BuildParams();}public Process GetProcess(string browerType){Process p = Process.GetCurrentProcess();List<Process> list = new List<Process>();foreach (var item in Process.GetProcesses()){if (item.ProcessName.Equals(browerType,StringComparison.CurrentCultureIgnoreCase)){list.Add(item);}}list.Sort((a, b) =>{return a.TotalProcessorTime.CompareTo(b.TotalProcessorTime);});//瀏覽器啟動時間排序return list[0];//返回瀏覽器啟動用時最少的
       }#endregion#region Findprivate T GetControl<T>(HtmlControl hc) where T : HtmlControl{T to = null;try{Type t = typeof(T);var types = new Type[1];types[0] = typeof(HtmlControl);ConstructorInfo ci = t.GetConstructor(types);var obj = new object[1];obj[0] = hc;to = (T)ci.Invoke(obj);}catch{to = default(T);}return to;}public T ByID<T>(string id) where T : HtmlControl{return ByID<T>(htmlDoc, id);}public T ByID<T>(HtmlControl hc, string id) where T : HtmlControl{return GetHtmlControlByProperty<T>(hc, "Id:"+id);}/// <summary>///Get Control By Propert. eg HtmlDiv hd=f.ByPropert<HtmlDiv>("Id:IdValue;Name:NamaValue")/// </summary>/// <typeparam name="T">ControlType</typeparam>/// <param name="attributeValue">Id:IdValue;Name:NamaValue</param>/// <returns>T</returns>public T ByPropert<T>(string propertyValue) where T : HtmlControl{return ByPropert<T>(htmlDoc, propertyValue);}public T ByPropert<T>(HtmlControl hc, string propertyValue) where T : HtmlControl{return GetHtmlControlByProperty<T>(hc, propertyValue);}public T GetHtmlControlByProperty<T>(HtmlControl hc, string propertyValue) where T: HtmlControl{T t = GetControl<T>(hc);try{if (!string.IsNullOrWhiteSpace(propertyValue)){string[] arr1 = propertyValue.Split(';');for (int i = 0; i < arr1.Length; i++){string[] arr2 = arr1[i].Split(':');t.SearchProperties[arr2[0]] = arr2[1];}}}catch { }return t;}#endregionpublic void Close(){browser.Close();Thread.Sleep(5000);}}
}

?

  

轉載于:https://www.cnblogs.com/jiebian/archive/2012/11/30/2796406.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377047.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377047.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377047.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

L8ER的完整形式是什么?

L8ER&#xff1a;稍后 (L8ER: Later) L8ER is an abbreviation of "Later". L8ER是“ Later”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo Messenger, and Gmail, etc…

Randomize select algorithm 隨機選擇算法

從一個序列里面選擇第k大的數在沒有學習算法導論之前我想最通用的想法是給這個數組排序&#xff0c;然后按照排序結果返回第k大的數值。如果使用排序方法來做的話時間復雜度肯定至少為O&#xff08;nlgn&#xff09;。 問題是從序列中選擇第k大的數完全沒有必要來排序&#xff…

《Linux雜記:一》

目錄CPU負載和CPU利用率CPU負載很高,利用率卻很低的情況負載很低,利用率卻很高常用linux命令常用的文件、目錄命令常用的權限命令常用的壓縮命令CPU負載和CPU利用率 可以通過 uptime , w 或者 top 命令看到CPU的平均負載。 Load Average :負載的3個數字,比如上圖的0.57、0.4…

IOS Plist操作

代碼&#xff1a;copy BUNDLE下的plist文件 到 library下面。 bundle下不支持些&#xff0c;library&#xff0c;doc路徑支持讀與寫。 (void)copyUserpigListToLibrary {NSFileManager *fileManager [NSFileManager defaultManager];NSArray *paths NSSearchPathForDirector…

《線程管理:線程基本操作》

目錄線程管理啟動線程與&#xff08;不&#xff09;等待線程完成特殊情況下的等待&#xff08;使用trycath或rall&#xff09;后臺運行線程線程管理 啟動線程與&#xff08;不&#xff09;等待線程完成 提供的函數對象被復制到新的線程的存儲空間中&#xff0c;函數對象的執行…

scala特質_Scala的特質

scala特質Scala特質 (Scala traits) Traits in Scala are like interfaces in Java. A trait can have fields and methods as members, these members can be abstract and non-abstract while creation of trait. Scala中的特性類似于Java中的接口 。 特征可以具有作為成員的…

優化PHP代碼的40條建議(轉)

優化PHP代碼的40條建議 40 Tips for optimizing your php Code 原文地址&#xff1a;http://reinholdweber.com/?p3 英文版權歸Reinhold Weber所有&#xff0c;中譯文作者yangyang&#xff08;aka davidkoree&#xff09;。雙語版可用于非商業傳播&#xff0c;但須注明英文版作…

Iptables入門教程

轉自&#xff1a;http://drops.wooyun.org/tips/1424 linux的包過濾功能&#xff0c;即linux防火墻&#xff0c;它由netfilter 和 iptables 兩個組件組成。 netfilter 組件也稱為內核空間&#xff0c;是內核的一部分&#xff0c;由一些信息包過濾表組成&#xff0c;這些表包含內…

《線程管理:傳遞參數、確定線程數量、線程標識》

參考《c Concurrency In Action 》第二章做的筆記 目錄傳遞參數量產線程線程標識傳遞參數 thread構造函數的附加參數會拷貝至新線程的內存空間中&#xff0c;即使函數中的采納數是引用類型&#xff0c;拷貝操作也會執行。如果我們期待傳入一個引用&#xff0c;必須使用std::re…

手把手玩轉win8開發系列課程(14)

這節的議程就是——添加appbar appbar是出現在哪兒了&#xff0c;出現在屏幕的底部。他能使用戶能用手勢或者使用鼠標操作程序。metro UI 重點是在主要的控件使用許多控件&#xff0c;使其用戶使用win8電腦更加的方便。而appBar使其用戶體驗更好。在這節中&#xff0c;我將告訴…

No identities are available for signing 的解決辦法

今天重新上傳做好的app提交到app store&#xff0c;結果就出現標題上的錯誤。“No identities are available for signing”。 以后碰到這樣的問題按照下面幾個步驟來做&#xff1a; 進入Distribution -----下載發布證書 -----雙擊安裝-----重啟Xcode就能上傳了 其他細節 如果再…

半連接反連接

半連接&反連接 1. 半連接 半連接返回左表中與右表至少匹配一次的數據行&#xff0c;通常體現為 EXISTS 或者 IN 子查詢。左表驅動右表。只返回左表的數據&#xff0c;右表作為篩選條件。 可以用 EXISTS、 IN 或者 ANY 舉例&#xff1a;表t1和表t2做半連接&#xff0c;t…

匿名方法和Lambda表達式

出于MVVM學習的需要&#xff0c;復習下匿名方法和Lambda表達式&#xff0c;因為之前用的也比較少&#xff0c;所以用的也不是很熟練&#xff0c;Baidu下相關的知識&#xff0c;寫了這個Demo&#xff0c;目標是用簡單的方法展示這個怎么用。 這里偏重的和LINQ中的Lambda表達式 …

爛橘子

Problem Statement: 問題陳述&#xff1a; Given a matrix of dimension r*c where each cell in the matrix can have values 0, 1 or 2 which has the following meaning: 給定尺寸r * C的矩陣&#xff0c;其中矩陣中的每個單元可以具有其具有以下含義的值0&#xff0c;1或2…

android junit 測試程序

http://blog.csdn.net/to_cm/article/details/5704783 Assert.assertEquals(2, t); 斷言轉載于:https://www.cnblogs.com/wjw334/p/3714120.html

MySQL 8.0.22執行器源碼分析HashJoin —— BuildHashTable函數細節步驟

BuildHashTable函數細節步驟 該函數位置處于hash_join_iterator.cc 403 ~ 560行 step1&#xff1a;如果被驅動表迭代器沒有更多的行數&#xff0c;更新m_state為EOR&#xff0c;然后返回false&#xff0c;表明創建hash表失敗 if (!m_build_iterator_has_more_rows) {m_state…

《那些年啊,那些事——一個程序員的奮斗史》——125

距離離職交接的一個月時間還剩幾天&#xff0c;本來應該是平淡無事的&#xff0c;卻沒想到最后還是波瀾四起。昨天下班前&#xff0c;公司突然停了電。這本是件普通得不能再普通的事情&#xff0c;可沒想到過了一會來電了&#xff0c;或許是波峰電壓太大&#xff0c;或許是穩壓…

python中的元類_Python中的元類

python中的元類Python元類 (Python metaclass) A metaclass is the class of a class. A class defines how an instance of a class i.e.; an object behaves whilst a metaclass defines how a class behaves. A class is an instance of a metaclass. 元類是類的類。 一個類…

MySQL 8.0.22執行器源碼分析HashJoin —— 一些初始化函數的細節步驟

目錄InitRowBuffer&#xff08;101行~126行&#xff09;InitProbeIterator&#xff08;142行~153行&#xff09;*HashJoinIterator* 的Init&#xff08;155行~240行&#xff09;InitializeChunkFiles&#xff08;364行~401行&#xff09;InitWritingToProbeRowSavingFile&#…

c語言的宏定義學習筆記

宏定義 在預處理之前&#xff0c;c預處理器會對代碼進行翻譯&#xff0c;譬如用blank替換注釋&#xff0c;去掉多余的空格&#xff0c;刪除末尾的\來拼接行等。 例如&#xff1a; int /*注釋*/ x; 會被翻譯成 int x; printf("this is a s\ entence."); 會被翻譯成 pr…