VS2017+Selenium测试脚本设计V1..docx

上传人:marr****208 文档编号:133695607 上传时间:2020-05-29 格式:DOCX 页数:20 大小:189.12KB
返回 下载 相关 举报
VS2017+Selenium测试脚本设计V1..docx_第1页
第1页 / 共20页
VS2017+Selenium测试脚本设计V1..docx_第2页
第2页 / 共20页
VS2017+Selenium测试脚本设计V1..docx_第3页
第3页 / 共20页
VS2017+Selenium测试脚本设计V1..docx_第4页
第4页 / 共20页
VS2017+Selenium测试脚本设计V1..docx_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《VS2017+Selenium测试脚本设计V1..docx》由会员分享,可在线阅读,更多相关《VS2017+Selenium测试脚本设计V1..docx(20页珍藏版)》请在金锄头文库上搜索。

1、目录脚本结构设计2VS2010 MSTest单元测试框架2Setup & TearDown2Case分类组织4UnitTest文件TestMethod测试用例5例子5封装检查点9封装调用10例-safeClick13对象管理与对象库设计14Open2Test的Framework for Selenium 214VS2010的App.config14面向页面对象设计模式15数据驱动17VS2010 数据驱动 Unit Test17Excel17ADO.NET18COM19截图19脚本结构设计VS2010 MSTest单元测试框架Setup & TearDownClassInitializeTes

2、tInitialize()属性表示测试初始化跑的地方TestCleanup()属性表示是每次执行完测试类后清除的东西也就是测试类最后跑的地方TestMethod1. ClassInitialize and ClassCleanup: Since ClassInitialize and ClassCleanUp are static, they are only executed once even though several instances of a test class can be created by MSTest. ClassInitialize executes in the

3、instance of the test class corresponding to the first test method in the test class. Similarly, MSTest executes ClassCleanUp in the instance of the test class corresponding to the last test method in the test class.2. Execution Interleaving: Since each instance of the test class is instantiated sepa

4、rately on a different thread, there are no guarantees regarding the order of execution of unit tests in a single class, or across classes. The execution of tests may be interleaved across classes, and potentially even assemblies, depending on how you chose to execute your tests. The key thing here i

5、s all tests could be executed in any order, it is totally undefined.3. TextContext Instances: TestContexts are different for each test method, with no sharing between test methods. For example, if we have a Test Class: TestClass public class VSTSClass1 private TestContext testContextInstance; public

6、 TestContext TestContext get return testContextInstance; set testContextInstance = value; ClassInitialize public static void ClassSetup(TestContext a) Console.WriteLine(Class Setup); TestInitialize public void TestInit() Console.WriteLine(Test Init); TestMethod public void Test1() Console.WriteLine(

7、Test1); TestMethod public void Test2() Console.WriteLine(Test2); TestMethod public void Test3() Console.WriteLine(Test3); TestCleanup public void TestCleanUp() Console.WriteLine(TestCleanUp); ClassCleanup public static void ClassCleanUp() Console.WriteLine(ClassCleanUp); (This consists of 3 Test Met

8、hods, ClassInitialize, ClassCleanup, TestInitialize, TestCleanUp and anexplicit declaration of TestContext)The execution order would be as follows:Test1 Thread 1: new TestContext - ClassInitialize - TestInitialize - TestMethod1 - TestCleanUpTest2 Thread 2: new TestContext - TestInitialize - TestMeth

9、od2 - TestCleanUpTest3 Thread 3: new TestContext - TestInitialize - TestMethod2 - TestCleanUp - ClassCleanUpThe output after running all the tests in the class would be:Class SetupTest InitTest1TestCleanUpTest InitTest2TestCleanUpTest InitTest3TestCleanUpClassCleanUpCase分类组织TestCategory分类,TestList中筛

10、选组织UnitTest文件TestMethod测试用例注意UnitTest文件和TestMethod的命名规范例子using System;using System.Text;using System.Collections.Generic;using System.Linq;using Microsoft.VisualStudio.TestTools.UnitTesting;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;/*namespace TestProject1 TestClass public class UnitTest1

11、TestMethod public void TestMethod1() IWebDriver driver = new FirefoxDriver(); driver.Url = http:/localhost:8080/AltoroJ/; driver.FindElement(By.Id(LoginLink).Click(); driver.Quit(); */*namespace TestProject1 TestClass public class UnitTest1 IWebDriver driver; TestInitialize public void Setup() drive

12、r = new FirefoxDriver(); TestMethod public void TestMethod1() driver.Url = http:/localhost:8080/AltoroJ/; driver.FindElement(By.Id(LoginLink).Click(); TestMethod public void TestMethod2() driver.Url = http:/localhost:8080/AltoroJ/; driver.FindElement(By.Id(query).SendKeys(hello!); TestCleanup public void TearDown() driver.Quit(); */*namespace TestPro

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号