我用Selenium做了一组IU测试,为它创建了一个类库,当它与VSTS集成时,我该怎么做才能在构建测试时运行测试?
答案 0 :(得分:-1)
如果是.net测试项目,您可以参考这篇文章:Get started with Selenium testing in a CI pipeline
简单步骤:
样品:
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()
{
}
}
}
您还可以使用Visual Studio Test任务运行测试(替换步骤6~9),博客:Running Selenium Tests as part of your release with VSTS Release Management