среда, 14 сентября 2011 г.

Subversion Plugin Mashups now are running by CI server

For a long time we have many mashups javascript unit tests implemented.

Until now they were runnable by hand only, but it's not an option.

There is a MashupSpecs C# unit test introduced today into Tp.Subversion.Tests.

It's written in C# with using of WebDriver. It opens a web page with javascript unit tests, then gathers results. If any errors acquired then it will fail the build.

Now it's quite simple implementation and may be improved:

[TestFixture]
	public class MashupSpecs
	{
		private IWebDriver _webDriver;
 
		[SetUp]
		public void Init()
		{
			_webDriver = new RemoteWebDriver(DesiredCapabilities.Firefox());
			_webDriver.Navigate().GoToUrl(string.Format(@"file:///{0}/UI/Tests/index.html"AppDomain.CurrentDomain.BaseDirectory));
		}
 
		[TearDown]
		public void Destroy()
		{
			_webDriver.Close();
			_webDriver.Dispose();
		}
 
		[Test]
		public void ShouldRunAllTests()
		{
			new WebDriverWait(_webDriverTimeSpan.FromSeconds(10)).Until(x => x.FindElement(By.Id("qunit-banner")).GetAttribute("class") != string.Empty);
			var failedTests = _webDriver.FindElements(By.CssSelector("#qunit-tests>.fail"));
			failedTests.Should(Be.Emptynew FailedTestCollection(failedTests).ToString());
		}
	}
 
	public class FailedTestCollection : ReadOnlyCollection<IWebElement>
	{
		public FailedTestCollection(IList<IWebElement> list)
			: base(list) {}
 
		public override string ToString()
		{
			var result = new StringBuilder();
			foreach (var webElement in Items)
			{
				result.AppendLine(webElement.Text);
				result.AppendLine();
			}
			return result.ToString();
		}
	}