-
Notifications
You must be signed in to change notification settings - Fork 8
Home
#Xenon#
Xenon is a framework which you can use in your acceptance tests to write tests in a fluent style. It can help you to write browser based non-flaky tests. We currently support Selenium as a browser automation driver to run the tests and we will support any other browser automation toolkit if requested.
##Installation## You can either download the source code and compile it on your machine or you can use nuget packages in your test project.
Since at the moment only Selenium is supported therefore you can just install Xenon.Selenium package which will copy the Xenon and Selenium packages as a dependency. To install the package, you need to write the following command in your Package Manager Console.
install-package Xenon.Selenium
or if you want to use a pre-released package then write
install-package Xenon.Selenium -pre
Now you need selenium browser driver file in which you want to run the test. We use chrome web driver but you are free to use any browser driver. If you want to use chrome driver in your tests then install the following package.
install-package Selenium.WebDriver.ChromeDriver
You need to install Nunit or Xunit or any other testing framework so that you can run your tests. If you haven't already installed then write the following command in your package manager console
install-package nunit
Now you've got everything which you need in order to write tests using Xenon, Selenium, and Chrome. Its time to write tests.
##How To Use##
###Example 1### This is a very simple example which will introduce you how to write tests using Xenon.
[TestFixture]
public class SearchXenon
{
[Test]
public void ShouldFindXenonInGoogleResults()
{
var browser = new SeleniumXenonBrowser( new ChromeDriver() );
new XenonTest( browser )
.GoToUrl( "http://www.google.com" )
.EnterText( "[name='q']", "Xenon is fantastic" )
.Click( "[name='btnG']" );
}
}
A pretty simple example, here you are creating a browser instance which is needed to create an instance of XenonTests and then you go to google.com, enter a search text and click submit button.
###Example 2### We will re-use the same example but in the end we want to assert that we are on the right page. So lets re-write it
[TestFixture]
public class SearchXenon
{
[Test]
public void ShouldFindXenonInGoogleResults()
{
XenonTestOptions.Options = new XenonTestOptions
{
AssertMethod = Assert.IsTrue,
WaitForSeconds = 5
};
var browser = new SeleniumXenonBrowser( new ChromeDriver() );
new XenonTest( browser )
.GoToUrl( "http://www.google.com" )
.EnterText( "[name='q']", "Xenon is fantastic" )
.Click( "[name='btnG']" )
.Assert( a => a.PageContains( "Search Results" ) );
}
}
Before writing your actual test, you need to set XenonTestOptions.Options property. This needs to be done only once so you can do this in your [SetUp] method or in [FixtureSetUp]. You can either specify XenonTestOptions when creating an instance of XenonTest or you can just set it once just like we did and use it globally for all tests.
In this example, we are setting WaitForSeconds property which guides Xenon that how long it should wait for something if it cannot find the element which you have specified in GoToUrl, EnterText, Click, or in any other method. The second property is AssertMethod which is actually the function name and Xenon calls this method whenever you assert something in your tests. Since we don't wanted to depend on any specific test framework like nunit or xunit therefore it is your job to set the appropriate assert method according to the test framework which you are using. As we are using nunit therefore we set the AssertMethod to Assert.IsTrue.
Well this would be enough to give you a head start. Let us know if you need any help.