当前位置: 首页 > news >正文

深圳入户申请网站官网央视优购物官方网站

深圳入户申请网站官网,央视优购物官方网站,免费asp网站后台管理系统,优化法治化营商环境#x1f525; 交流讨论#xff1a;欢迎加入我们一起学习#xff01; #x1f525; 资源分享#xff1a;耗时200小时精选的「软件测试」资料包 #x1f525; 教程推荐#xff1a;火遍全网的《软件测试》教程 #x1f4e2;欢迎点赞 #x1f44d; 收藏 ⭐留言 #x1… 交流讨论欢迎加入我们一起学习 资源分享耗时200小时精选的「软件测试」资料包  教程推荐火遍全网的《软件测试》教程   欢迎点赞 收藏 ⭐留言 如有错误敬请指正 PS这次用公司的项目来练手希望公司不会起诉我因为我绝对是抱着学习的态度没有任何恶意。仅供交流学习。 该项目是基于SharePoint平台所开发的门户网站为了切身感受一下Selenium 2.0我决定自己动手写一个自动化测试用例而不是通过录制的方式以加深我对一些web操作的理解。 我设计的测试用例是检查Staff Spotlight中所包含的item对应三级页面显示的信息是否正确。具体逻辑是在英语浏览器下检查后台list中英语Column的value和三级page中对应Column的value是否一致在日语浏览器下检查后台list中日语Column的value和三级page中对应Column的value是否一致如果是英语浏览器下后台list中没有勾选“English Ready”项则在三级page中显示日语Column的value。 三级page如下 点击页面右上角的“Edit Item”按钮可以跳转到后台list中相应的item编辑页面点击上方的“日本语”按钮可以进行英语和日语的语言切换点击“日本语”将切换到日本语再点击“English”将切换到英语。 我们本次要取的页面元素就是DepartmentLocationTitle以及Join Date的页面value。然后点击“Edit Item”按钮跳转到后台item编辑页面按“F12”找到对应要获取的后台元素值 获取到对应的Column的value所在页面的元素然后获取页面上显示的值将其与三级page上的value按我们之前说过的逻辑进行比对如果一样测试通过如果不一样测试失败。 代码如下 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenQA.Selenium; using OpenQA.Selenium.IE; using OpenQA.Selenium.Support; using OpenQA.Selenium.Support.UI; using Selenium; using mySelenium; using System.Runtime.InteropServices; using System.Threading; using System.Diagnostics; using System.Net; using System.IO; using System.Globalization;namespace mySelenium {class LoginSPSite{[DllImport(user32.dll, CharSet CharSet.Auto, ExactSpelling true)]public static extern IntPtr GetForegroundWindow();static void Main(string[] args){IWebDriver driver new InternetExplorerDriver();IWebDriver iw login(driver,https://insite.ccqa11apps.com/Pages/default.aspx);INavigation navi iw.Navigate();string language checkLanguage(iw);if (language English){//Check the English page.检查英语页面信息。Console.ForegroundColor ConsoleColor.Yellow;Console.WriteLine(--English page check--);checkPageInfo(iw,En);//Turn to the Japanese page.转换到日语页面。navi.GoToUrl(https://insite.ccqa11apps.com/Pages/default.aspx);waitUntilPageLoaded(iw, ctl00_ctl21_ToggleLanguage);iw.FindElement(By.Id(ctl00_ctl21_ToggleLanguage)).Click();//Check the Japanese page.检查日语页面信息。Console.ForegroundColor ConsoleColor.Yellow;Console.WriteLine(--Japanese page check--);checkPageInfo(iw,Ja);}//Language is Japanese.else {//Check the Japanese page.检查日语页面信息。Console.ForegroundColor ConsoleColor.Yellow;Console.WriteLine(--Japanese page check--);checkPageInfo(iw,Ja);//Turn to the English page.转换到英语页面。navi.GoToUrl(https://insite.ccqa11apps.com/Pages/default.aspx);waitUntilPageLoaded(iw, ctl00_ctl21_ToggleLanguage);iw.FindElement(By.Id(ctl00_ctl21_ToggleLanguage)).Click();//Check the English page.检查英语页面信息。Console.ForegroundColor ConsoleColor.Yellow;Console.WriteLine(--English page check--);checkPageInfo(iw, En);}}//Get the 3rd page info.从三级page中获取指定的Column的value需要传入IWebDriver对象以及当前页面的语言种类。private static void checkPageInfo(IWebDriver iw,string LanType){//Check 3rd page with the format: https://insite.ccqa11apps.com/_layouts/15/InSite/pages/StaffDetails.aspx?id under the English environment.INavigation navi iw.Navigate();for (int i 1; i 5; i){Console.ForegroundColor ConsoleColor.White;Console.WriteLine(This is the i staff item check info:);navi.GoToUrl(https://insite.ccqa11apps.com/_layouts/15/InSite/pages/StaffDetails.aspx?id i.ToString());var eles iw.FindElements(By.ClassName(apps-staffdetail-content-splitline));//Get the info from the 3rd page.获取三级page上Column的value信息。StaffSpotlight staffSpotlight new StaffSpotlight();staffSpotlight.Department eles[0].FindElement(By.ClassName(apps-staffdetail-content-splitline-bottom)).Text;staffSpotlight.Location eles[1].FindElement(By.ClassName(apps-staffdetail-content-splitline-bottom)).Text;staffSpotlight.Title eles[2].FindElement(By.ClassName(apps-staffdetail-content-splitline-bottom)).Text;staffSpotlight.JoinDate eles[3].FindElement(By.ClassName(apps-staffdetail-content-splitline-bottom)).Text;//Find the Edit Item button.找到“Edit Item”按钮并点击。iw.FindElement(By.ClassName(apps-staffdetail-edit)).Click();//Wait until the element on page loaded.等待页面元素加载完成。waitUntilPageLoaded(iw, Inpex_Department_$containereditableRegion);//Get the info from the backend list.获取后台list中Column的value信息。StaffSpotlight staffInfoFromBackend new StaffSpotlight();staffInfoFromBackend.Department iw.FindElement(By.Id(Inpex_Department_$containereditableRegion)).FindElement(By.ClassName(valid-text)).Text;staffInfoFromBackend.Location iw.FindElement(By.Id(Inpex_Office_$containereditableRegion)).FindElement(By.ClassName(valid-text)).Text;//Job title is the title under English IE.Title是日语浏览器中显示的TitleEnTitle是英语浏览器中显示的Title。staffInfoFromBackend.Title iw.FindElement(By.Id(Inpex_Job_Title_30756774-5931-4844-bac1-a2f463d04ca0_$TextField)).GetAttribute(value).ToString();staffInfoFromBackend.EnTitle iw.FindElement(By.Id(Inpex_Job_Title_E_ef6d11a7-f73e-4885-bef1-527a1c03c924_$TextField)).GetAttribute(value).ToString();staffInfoFromBackend.JoinDate iw.FindElement(By.Id(Inpex_Join_Date_b133dcfe-4e0c-4f0f-8b82-92a549516e6d_$DateTimeFieldDate)).GetAttribute(value).ToString();//Compare the actual 3rd info with the expected backend info.将三级page中的Column value和预期value比较。Compare(Department, staffSpotlight.Department, staffInfoFromBackend.Department);Compare(Location, staffSpotlight.Location, staffInfoFromBackend.Location);//英语页面的Title信息比对检查逻辑。if (LanType En){try{ //If can get the element underneath, it means English Ready has been checked.如果可以在页面上获取到该元素说明“English Ready”这一项是勾选的。string ifChecked iw.FindElement(By.Id(Inpex_E_Text_a355a229-a1bb-48f5-81dd-e428a0d4fbd2_$BooleanField)).GetAttribute(checked).ToString();Console.WriteLine(The Englisht ready has been checked: ifChecked);//Compare the title with the backend En one.比对EnTitle和三级page中的Column value是否一致。Compare(Title, staffSpotlight.Title, staffInfoFromBackend.EnTitle);}//If can not get the element by the ID above, it means English Ready has not been checked.如果获取不到“English Ready”元素下的“checked” Attribute说明没勾选。catch(Exception ex){WriteLog(ex);//Compare the title with the backend Jp one.比对Title和三级page中的Column value是否一致。Console.WriteLine(The Englisht ready has been checked: false);Compare(Title, staffSpotlight.Title, staffInfoFromBackend.Title);} }//日语页面的Title信息比对检查逻辑。else {staffInfoFromBackend.Title iw.FindElement(By.Id(Inpex_Job_Title_30756774-5931-4844-bac1-a2f463d04ca0_$TextField)).GetAttribute(value).ToString();Compare(JapTitle, staffSpotlight.Title, staffInfoFromBackend.Title);}//Change the time format into the same.统一转换三级page上的join date时间格式以及后台list item的join date时间格式并进行比较。string joinDateOnPage;string joinDateFromBackend;if (staffSpotlight.JoinDate ! ){DateTime dt Convert.ToDateTime(staffSpotlight.JoinDate);joinDateOnPage dt.ToString(yyyy-MM-dd);}else {joinDateOnPage ;}if (staffInfoFromBackend.JoinDate ! ){DateTime dt2 Convert.ToDateTime(staffInfoFromBackend.JoinDate);joinDateFromBackend dt2.ToString(yyyy-MM-dd);}else {joinDateFromBackend ;}Compare(JoinDate, joinDateOnPage, joinDateFromBackend);}}//Compare value method.传入对应要检查的Column的标题三级page中Column的value后台list中item对应Column的value。private static void Compare(string title, string p1, string p2){if (p1 p2){Console.ForegroundColor ConsoleColor.Green;Console.WriteLine(title info on the 3rd page has passed the check.);}else {Console.ForegroundColor ConsoleColor.Red;Console.WriteLine(title info on the 3rd page has not passed the check.);Console.WriteLine(The info on the 3rd page: p1);Console.WriteLine(The info from the backend page: p2);}}//Check language method.检查当前页面所处于的语言环境判断是英语还是日语并返回当前语言种类。private static string checkLanguage(IWebDriver iw){string currentLanguage;//Wait until the element on page loaded.waitUntilPageLoaded(iw, ctl00_ctl21_ToggleLanguage);string language iw.FindElement(By.Id(ctl00_ctl21_ToggleLanguage)).Text;if (language.Length 3){currentLanguage English;return currentLanguage;}else {currentLanguage Japanese;return currentLanguage;}}//Wait until loaded method.等待网页加载完毕指定元素如果没有加载完获取不到捕获异常继续等待直到指定元素加载完毕。private static void waitUntilPageLoaded(IWebDriver iw, string element){try{iw.FindElement(By.Id(element));}catch (Exception ex){WriteLog(ex);Thread.Sleep(2000);waitUntilPageLoaded(iw, element);}}//Login method.登陆网站的方法需要传入IWebDriver对象以及网站的url。public static IWebDriver login(IWebDriver driver, string url) {INavigation navigation driver.Navigate();navigation.GoToUrl(url);driver.FindElement(By.Id(overridelink)).Click();IntPtr myPtr GetForegroundWindow();//IntPtr hWnd FindWindow(null, abc);if (myPtr ! IntPtr.Zero){//Send message to the window.System.Windows.Forms.SendKeys.SendWait(dswu);System.Windows.Forms.SendKeys.SendWait({TAB});System.Windows.Forms.SendKeys.SendWait(1qaz2wsxE);System.Windows.Forms.SendKeys.SendWait({ENTER});}return driver;}//Write log method.将捕获到的异常打印到本地log文件中。private static void WriteLog(Exception ex){string logUrl Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) \\SeleniumAutoTest.txt;if (File.Exists(logUrl)){using (FileStream fs new FileStream(logUrl, FileMode.Append)){using (StreamWriter sw new StreamWriter(fs, Encoding.Default)){try{sw.Write(ex);}catch (Exception ex1){WriteLog(ex1);}finally{sw.Close();fs.Close();}}}}else{using (FileStream fs new FileStream(logUrl, FileMode.CreateNew)){using (StreamWriter sw new StreamWriter(fs, Encoding.Default)){try{sw.Write(ex);}catch (Exception ex1){WriteLog(ex1);}finally{sw.Close();fs.Close();}}}}}} } 这里我创建一个类用来存储三级page以及后台list中获取到的Staff item的信息 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace mySelenium {class StaffSpotlight{public string Department { get; set; }public string Location { get; set; }public string Title { get; set; }public string EnTitle { get; set; }public string JoinDate { get; set; }} } 按F5进行测试结果如下 测试通过。 覆盖多浏览器在Selenium也是很容易实现的只需要把IE打开方法改用为指定浏览器所对应的打开方法 IWebDriver driver  new InternetExplorerDriver();  把这句换了之后的步骤对应做些修改即可。 自动化测试从某些方面讲确实是一劳永逸的但是有很多时候自动化测试是完全没有必要的尤其是项目周期很短的情况下自动化的封装应该更偏向于具有普遍性的可复用过程而不是业务逻辑。 有时候产出决定付出。我们没必要为了一个两三月交付的项目写一堆自动化测试用例否则得不偿失。自动化测试应该更偏向于长期上线、持续迭代的项目展开否则最后失落感是一定有的。 最后我邀请你进入我们的【软件测试学习交流群785128166】 大家可以一起探讨交流软件测试共同学习软件测试技术、面试等软件测试方方面面还会有免费直播课收获更多测试技巧我们一起进阶Python自动化测试/测试开发走向高薪之路 作为一个软件测试的过来人我想尽自己最大的努力帮助每一个伙伴都能顺利找到工作。所以我整理了下面这份资源现在免费分享给大家有需要的小伙伴可以关注【公众号程序员二黑】自提
http://www.dnsts.com.cn/news/248671.html

相关文章:

  • 盛锡福网站wordpress管理员用户名更改
  • 定制网站开发蒙特魔兽世界做宏网站
  • 招聘高级网站建设网站被做301
  • 上海市崇明县建设中学网站上海网站推广策划
  • 网站建设课程设计实验指导书个人网站的制作代码
  • 食品营销型网站建设中国互联网前100名企业
  • 后缀是.cc的网站网页布局的基本概念
  • 互联网风格网站wordpress 修订
  • 公司做网站的好处网络游戏称号大全
  • 做废品推广哪个网站好制作论坛做网站
  • 网站窗口建设企业建设网站的帮助
  • 南宁老牌网站建设公司做app和网站哪个比较好
  • 高清免费爱做网站成全视频免费观看在线看第6季
  • 专业网站建设找哪家公司腾讯云服务器免费领取
  • 如何用ftp做网站做网站之前需要准备什么软件
  • 最新网站建设网店代运营销售
  • 建设企业网站流程潍坊网站建设教程
  • 代做论文网站对网站建设的具体想法
  • 做ppt会去什么网站找图网站主机多少钱
  • 宁波市有哪些网站建设公司公司企业网站
  • 国土资源集约化网站群建设通知注册公司的具体流程
  • 建网站要使用哪些软件网络销售就是忽悠人
  • 辽宁省住房和城乡建设厅网站首页网站建设捌金手指专业5
  • 怎么做自己的快递查询网站给你一个网站seo如何做
  • 东莞效果好的营销型网站建设手机网站如何开通微信公众号
  • 建一个网站需要做什么的怎样才能有自己的网站
  • 东莞网站建设营销哪家好深圳建筑设计公司排行榜
  • 模板网站哪家好有做美食的视频网站么
  • 沧州做网站推广公司网站的基础服务
  • 做响应式网站的菜单栏做电商网站公司