将测试Selenium与VSTS集成

时间:2018-01-22 17:41:56

标签: selenium-webdriver azure-pipelines

我用Selenium做了一组IU测试,为它创建了一个类库,当它与VSTS集成时,我该怎么做才能在构建测试时运行测试?

1 个答案:

答案 0 :(得分:-1)

如果是.net测试项目,您可以参考这篇文章:Get started with Selenium testing in a CI pipeline

简单步骤:

  1. 创建单元测试项目
  2. 将Selenium.WebDriver,Selenium.WebDriver.ChromeDriver,Selenium.WebDriver.IEDriver,Selenium.Firefox.WebDriver,Selenium.WebDriver.PhantomJS.Xplatform包添加到您的项目中
  3. 编码
  4. 样品:

    namespace Partsunlimited.UITests
    {
      using Microsoft.VisualStudio.TestTools.UnitTesting;
      using OpenQA.Selenium;
      using OpenQA.Selenium.Chrome;
      using OpenQA.Selenium.Firefox;
      using OpenQA.Selenium.IE;
      using OpenQA.Selenium.Remote;
      using OpenQA.Selenium.PhantomJS;
      using System;
    
      [TestClass]
      public class ChucksClass1
      {
        private string baseURL = "http://your-website.azurewebsites.net/";
        private RemoteWebDriver driver;
        private string browser;
        public TestContext TestContext { get; set; }
    
        [TestMethod]
        [TestCategory("Selenium")]
        [Priority(1)]
        [Owner("FireFox")]
    
        public void TireSearch_Any()
        {
          driver = new FirefoxDriver();
          driver.Manage().Window.Maximize();
          driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
          driver.Navigate().GoToUrl(this.baseURL);
          driver.FindElementById("search - box").Clear();
          driver.FindElementById("search - box").SendKeys("tire");
          //do other Selenium things here!
        }
    
        [TestCleanup()]
        public void MyTestCleanup()
        {
          driver.Quit();
        }
    
        [TestInitialize()]
        public void MyTestInitialize()
        {
        }
      }
    }
    
    1. 创建新的构建定义
    2. 添加NuGet任务以恢复包
    3. 添加Visual Studio构建任务以构建项目
    4. 添加Visual Studio测试代理部署任务以部署测试代理
    5. 添加Windows计算机文件复制以将文件复制到代理计算机
    6. 添加运行功能测试任务以运行测试
    7. 您还可以使用Visual Studio Test任务运行测试(替换步骤6~9),博客:Running Selenium Tests as part of your release with VSTS Release Management