Writing test code based on RanoreXPath is not a big challenge. In fact, it’s always the same procedure. First, find the element within a web page. After that, automate it (click, set value,…). Two simple steps. Nevertheless, the bigger your test code the more structured and well designed it should be.

RanoreXPath allows many different ways of searching for web elements within a web page. The use of Ranorex WebSpy could tempt someone to always copy & paste RanoreXPaths from WebSpy into the test automation code. What an easy job. But consider that searching elements from scratch permanently could be time consuming, especially if using optimized RanoreXPaths. Moreover, the resulting test automation code is not as readable as we would like to have it. Take a look at following code lines:

view plaincopy to clipboardprint
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Ranorex;
  5. using Ranorex.Web;
  6. namespace WebTestDont
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. // Resource based identification of web elements
  13. WebDocument exampleDoc = WebDocument.OpenDocument(”www.ranorex.com/web-testing-examples”, true);
  14. // Find ‘Name’ textbox within form
  15. WebElement name = exampleDoc.FindSingle(”//input[@id='testname']“);
  16. Mouse.MoveToWebElement(name);
  17. name.Value = “Mr. XYZ”;
  18. // Find ‘Color’ drop down box within form
  19. WebElement colorSelector = exampleDoc.FindSingle(”//select[@id='testcolor']“);
  20. Mouse.MoveToWebElement(colorSelector);
  21. colorSelector.Value = “blue”;
  22. // … search for next elements …
  23. }
  24. }
  25. }
using System;
using System.Collections.Generic;
using System.Text;
using Ranorex;
using Ranorex.Web;
namespace WebTestDont
{class Program{static void Main(string[] args){// Resource based identification of web elementsWebDocument exampleDoc = WebDocument.OpenDocument(”www.ranorex.com/web-testing-examples”, true);// Find ‘Name’ textbox within formWebElement name = exampleDoc.FindSingle(”//input[@id='testname']“);Mouse.MoveToWebElement(name);name.Value = “Mr. XYZ”;// Find ‘Color’ drop down box within formWebElement colorSelector = exampleDoc.FindSingle(”//select[@id='testcolor']“);Mouse.MoveToWebElement(colorSelector);colorSelector.Value = “blue”;// … search for next elements …}}
}

I know, the few code lines above don’t give a good example for a long and unreadable test code. But what we can see, is that the example always starts the element search from scratch by calling the method ‘FindSingle’ from the ‘exampleDoc’ object. Another problem is the use of hard-coded RanoreXPath expressions. Due to changes within your AUT (application under test) you may need to update your code lines with new RanoreXPath expressions, to ensure your test is still workable .

For that reason it’s advisable to extract and separate your RanoreXPath search strings from your test codes. There are many different types to generate global mapping/resource information. The next section concentrates on the use of resource files provided by Microsoft Visual Studio.

Visual Studio provides resource files for storing several types of objects (Images, Icons, Strings, …). Our use case only requires a resource table of type string. Simple add a new resource file called ‘GuiMapping’ to your Visual Studio project.

To add a resource file please

  • open your Visual Studio project properties and
  • add a new resource within the ‘Resource’ tab.

The use of resource files extracts complex search strings from test code and concentrates searching information at one single location. The static ‘GuiMapping’ object is easy to use during coding and provides all necessary RanoreXPath expressions. In addition to that, the following implementation speeds up the search of web elements: In the first step we search for the web element of type ‘form’. After that, each search for web elements located within this form can be done by calling the method ‘FindSingle’ on the form object.

view plaincopy to clipboardprint
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Ranorex;
  5. using Ranorex.Web;
  6. namespace WebTest
  7. {
  8. // Using 'Properties' namespace to access
  9. // Resource elements
  10. using Properties;
  11. class Program
  12. {
  13. [STAThread]
  14. static void Main(string[] args)
  15. {
  16. // Resource based identification of web elements
  17. WebDocument exampleDoc = WebDocument.OpenDocument(GuiMapping.WebTestUrl, true);
  18. WebElement form = exampleDoc.FindSingle(GuiMapping.WebTestForm);
  19. // Find ‘Name’ textbox within form
  20. WebElement name = form.FindSingle(GuiMapping.WebTestName);
  21. Mouse.MoveToWebElement(name);
  22. name.Value = “Mr. XYZ”;
  23. // Find ‘Color’ drop down box within form
  24. WebElement colorSelector = form.FindSingle(GuiMapping.WebTestColors);
  25. Mouse.MoveToWebElement(colorSelector);
  26. colorSelector.Value = “blue”;
  27. }
  28. }
  29. }
using System;
using System.Collections.Generic;
using System.Text;
using Ranorex;
using Ranorex.Web;
namespace WebTest
{// Using 'Properties' namespace to access// Resource elementsusing Properties;class Program{[STAThread]static void Main(string[] args){// Resource based identification of web elementsWebDocument exampleDoc = WebDocument.OpenDocument(GuiMapping.WebTestUrl, true);WebElement form = exampleDoc.FindSingle(GuiMapping.WebTestForm);// Find ‘Name’ textbox within formWebElement name = form.FindSingle(GuiMapping.WebTestName);Mouse.MoveToWebElement(name);name.Value = “Mr. XYZ”;// Find ‘Color’ drop down box within formWebElement colorSelector = form.FindSingle(GuiMapping.WebTestColors);Mouse.MoveToWebElement(colorSelector);colorSelector.Value = “blue”;}}
}

For that reason, outsourcing of searching criteria enhances readability and coding maintenance for future extensions.

转载于:https://www.cnblogs.com/starspace/archive/2008/10/22/1316838.html

Global GUI map for automation with VS.NET相关推荐

  1. 一些常用模块的测试用例

    1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上的要求) ④密码符合要求 ...

  2. web常用模块的测试用例

    一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上 ...

  3. web常用模块测试用例

      一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格 ...

  4. cc笔记_web测试用例

    一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上 ...

  5. 测试基本技巧与方法;

    一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上 ...

  6. 关于测试中常用到的一些方法、策略总结

    一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上 ...

  7. 常用测试用例模板大全

    一些常用模块的测试用例 1.登录 2.添加 3.查询 4.删除 1.登录 ①用户名和密码都符合要求(格式上的要求) ②用户名和密码都不符合要求(格式上的要求) ③用户名符合要求,密码不符合要求(格式上 ...

  8. 软件测试自动化测试工具课件,《软件测试自动化》PPT课件.ppt

    <<软件测试自动化>PPT课件.ppt>由会员分享,可在线阅读,更多相关<<软件测试自动化>PPT课件.ppt(34页珍藏版)>请在装配图网上搜索. 1 ...

  9. ETL AUTOMATION介绍

    /**********************************/ 目录: 第一部分:ETL Automation简介 第二部分:ETL Automation架构 第三部分:ETL Automa ...

最新文章

  1. Megengine量化
  2. python re match groups_python re.match与re.search的区别
  3. vim 多文件编辑【超实用】
  4. iOS RunLoop 初识
  5. 一次高烧期间的感悟……
  6. BZOJ 1012: [JSOI2008]最大数maxnumber 单调队列/线段树/树状数组/乱搞
  7. 机器学习资料合计(二)
  8. cocos2d-x游戏开发 跑酷(四) 关联与物理世界
  9. php中对ASCII码的处理ord() 、chr()
  10. petshop4.0 详解之一(系统架构设计)(转载)
  11. 晨哥真有料丨到底合适重要,还是感觉重要!
  12. 增长是一切企业问题解决的入口
  13. 图标缩排和悬浮突显的简单实现
  14. 打造自己的Android源码学习环境之三:在虚拟机中安装Ubuntu(下)
  15. 电脑键盘部分按键失灵_笔记本键盘失灵怎么办,电脑键盘失灵-中关村在线
  16. python三维图形注释_Python使用注释绘制3D点
  17. vector的底层实现!(万字长文详解!)
  18. Windows文件名太长无法删除
  19. jzoj2742. 【PKU1625】Censored!
  20. javascript成神之路(1):如何编写高质量的js代码

热门文章

  1. bzoj 3357: [Usaco2004]等差数列(DP+map)
  2. bzoj 4236: JOIOJI(map+pair)
  3. bzoj 1045: [HAOI2008]糖果传递
  4. 莫烦python学习笔记之numpy.array,dtype,empty,zeros,ones,arrange,linspace
  5. 吴恩达神经网络和深度学习-学习笔记-38-使用开源的方案+迁移学习+数据增强data augmentation
  6. [PyTorch] 基于Python和PyTorch的线性拟合
  7. Python下APScheduler的快速指南
  8. 【paper and code】AC-GAN
  9. 新兴的人工智能服务器,5个新兴人工智能物联网应用
  10. 解决Python查询Mysql中文乱码问题