Send mail to the author(s) E-mail

# Thursday, 30 April 2015

Base class

  • setup and teardown
  • login
  • waiting for some time
| | # 
# Wednesday, 29 April 2015

Interesting code:

[TestClass] public class LoginTests { [TestInitialize] public void Init() { // Singleton to make writing tests easier Driver.Initialize(); } [TestMethod] public void Admin_User_Can_Login() { LoginPage.GoTo(); LoginPage.LoginAs("dave").WithPassword("letmein").Login(); Assert.IsTrue(DashboardPage.IsAt, "Failed to login"); } [TestCleanup] public void CleanUp() { // Using our Driver class, so don't have to talk to IWebDriver directly (which has a Close method) Driver.Close(); } }


public class Driver { public static IWebDriver Instance { get; set; } public static void Initialize() { Instance = new FirefoxDriver(); Instance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); } public static void Close() { //Instance.Close(); } }


public class LoginPage { public static void GoTo() { //Driver.Instance.Navigate().GoToUrl("http://localhost:46780/wp-login.php"); // work Driver.Instance.Navigate().GoToUrl("http://localhost:19461/wp-login.php"); // home } public static LoginCommand LoginAs(string userName) { return new LoginCommand(userName); } } public class LoginCommand { private readonly string userName; private string password; public LoginCommand(string userName) { this.userName = userName; } public LoginCommand WithPassword(string password) { this.password = password; // Returning the LoginCommand object return this; } public void Login() { var loginInput = Driver.Instance.FindElement(By.Id("user_login")); loginInput.SendKeys(userName); var passwordInput = Driver.Instance.FindElement(By.Id("user_pass")); passwordInput.SendKeys(password); var loginButton = Driver.Instance.FindElement(By.Id("wp-submit")); loginButton.Click(); } }

What to do with smoke tests?

  • Get it running at part of build process
  • Make sure developers can run it locally
| | # 
# Monday, 27 April 2015

Why BAT?

  • Regression “it worked yesterday!”
  • Absolute requirements
  • BATs test more production code with fewer lines of BAT code

Common Failure Points

  • Recorded brittle tests (it is fast… but something changes.. which causes things to break)
  • Not building a framework
  • Writing tests like code

Smoke testing… the widest tests… most basic functionality

The Page Pattern

A Class for each page (or section eg Header)
Methods for each piece of functionality/actions that a user can do

Basic Rules

  • Never require tests to declare variables
  • Never require tests to use new keyword
  • Never require tests to manage state
  • Never expose the browser or DOM to the tests or let them manipulate it directly
  • Always reduce the number of parameters for API calls
  • Always use default values instead of requiring parameters
  • Prefer to make the API easier to use over making the API less complex
  • Prefer enums and constants (ie restrict input values where possible)

Static Methods

Ok optimising for ease of use over maintenance for the framework itself..

most of the time production code we are optimising for maintainability and understand ability, so don’t use Static methods.

Smoke Tests

Core functionality / basic things.. with wide brush strokes…simple.. to determine any major problems

  • Login
  • Create new post
  • Edit an existing page

Creating a Solution

Selenium WebDriver
Selenium WebDriver Support Classes

First test – launches a browser (FF is default) and test passes (there are no conditions)

public class Class1 { public void Go(){ var driver = new FirefoxDriver(); //driver.Navigate().GoToUrl(""); driver.Navigate().GoToUrl(""); } }
| | # 
# Monday, 12 July 2010

A web application testing system

Selenium Remote Control runs tests in multiple browsers.. can do in C#

Selenium Grid can distribute tests across multiple servers.

Here is a console, running in C# calling the Selenium libraries, which call a java webserver

To start the server dowloads\selenium-remote-control-1.0.3   java -jar selenium-server.jar

There did seem to be an issue with the include statement of the Selenium core.. I got it working by deleing the using statement, then Ctrl . somewhere..  code in C:\code\SeleniumTest


It is easy to put in a rough speed test (8secs here.. was 45 secs with no caching and having to start up the webserver after having left it).

To explore soon:

- Fill out forms

- Actual assertions (can use nUnit)

- Handle ‘test’ edition of sitefinity gracefully

- Force no cache on browser

- Test functionality of site on different browsers

| | #