Starcounter
HomeDownloadDocsCommunity
2.3.1
2.3.1
  • Starcounter Documentation
  • Getting Started
  • Starcounter
    • Collapsing the Stack
      • Complexity and Scalability Tradeoff
      • The Future of Micro-Services
      • 10 Benefits of Collapsing the Stack
    • Integrated Database and Web Server
  • Hello World - Tutorial
    • Create a Database Class
    • Create a Real Time UI
    • First Interactive UI
    • Computed Properties
    • Expense Tracker
    • Cancel and Delete
    • The Next Step
  • Guides
    • Database
      • Database Classes
      • Data manipulation
      • Object Identity and Object References
      • Querying with SQL
      • Data Types
      • Relations
      • Inheritance
      • Sharing data
      • Database Configuration
      • Comparing Database Objects
      • Referential Integrity and Constraints
    • SQL
      • Identifiers
      • Path Expressions
      • Data operators
      • Joins
      • Aggregates
      • Comparisons and Logical Operators
      • Sorting
      • Fetch
      • Offset Key
      • Indexes
      • Literals
      • Query Plan Hints
      • Reserved words
      • Query for Database Classes
      • SQL Isolation Between Applications
    • Transactions
      • Short-Running Transactions
      • Long running transactions
      • Using Transactions
      • Running Background Jobs
      • Commit Hooks
    • Typed JSON
      • JSON-by-example
      • Code-Behind
      • Data Bindings
      • Callback Methods
      • Responding with JSON
      • Accepting JSON in Requests
      • Primitive Arrays and Single Value Types
      • Typed JSON Internals
    • Blendable Web Apps
      • Starcounter MVVM
      • Palindrom
      • Client-Side Stack
      • Sessions
      • HTML Views
      • App Shell
      • Web Components
      • View Attaching
      • View Composing
      • HTML Compositions
      • HTML Views Blending Guidelines
      • Avoiding CSS conflicts
      • Debugging
    • Network
      • HTTP
      • Internal Self Calls
      • Middleware
      • Anonymous or Substitute Handlers
      • URL Aliases and Redirects
      • Network Gateway
      • Static File Server
      • External HTTP Calls
      • WebSocket
      • Avoiding URI conflicts
      • TCP Sockets
      • UDP Sockets
    • Publishing Apps
    • Working with Starcounter
      • Release Channels
      • Starting and Stopping Apps
      • Administrator Web UI
      • Star CLI
      • StarAdmin CLI
      • StarDump CLI
      • Working in Visual Studio
      • Error Log
      • Using HTTPS on NGINX
      • Using HTTPS on IIS
      • Run Starcounter in Production
      • Weaver
      • Investigating App Crashes
      • Configuration Structure
      • Database Refactoring
      • Using Unload/Reload to Modify Database Schema
      • Kernel Questions and Answers
      • Log Files
  • Cookbook
    • Attach an HTTP Request to an Existing Long-Running Transaction
    • Cookie-Based Authentication
    • Timestamp on Object Creation
    • Creating Strongly Typed JSON Collections
    • Migrating From 2.2 to 2.3+
    • Multiple Pages
    • Icons
    • Proposed Project Structure
    • Acceptance Testing with Selenium
    • Requesting a User to Authenticate
    • How to delete unused tables and columns
Powered by GitBook
On this page
  • What is Selenium
  • What is NUnit
  • Create a Test Project
  • Install Required Packages
  • Running in Multiple Browsers
  • Install Selenium Standalone Server and Browser Drivers
  • Use BaseTest Class to Run Tests in Multiple Browsers
  • Wait for Asynchronous Content
  • Run the First Test
  • Sample Test Suites
  1. Cookbook

Acceptance Testing with Selenium

PreviousProposed Project StructureNextRequesting a User to Authenticate

Last updated 7 years ago

Puppet web apps are C# apps with a thin presentation layer rendered in HTML5. Because of that, acceptance tests need to be executed in a web browser. If you would like to add automated acceptance testing to your project, there is no better tool than Selenium.

This page teaches how to use NUnit to run Selenium acceptance tests of a Starcounter Puppet web app. It is assumed here that you are using Visual Studio 2015, though it should also work with the older editions.

What is Selenium

Selenium is a free (open source) automated testing suite for web applications across different browsers and platforms.

Selenium is not just a single tool but a suite of tools, each catering to different testing needs. The components that we will use are:

  1. Selenium WebDriver, which is an API that controls the web browser. It is implemented in all major programming languages, including C#.

  2. Selenium RemoteWebDriver, a Selenium WebDriver implementation that we will use, because it allows to execute the tests on the same or different machine. It is implemented in all major programming languages, including C#.

  3. Selenium Server Standalone, a Java-based server that runs specific web browser client drivers. RemoteWebDrivers runs the tests through it.

  4. Selenium client drivers for web browsers such as Firefox, Chrome and Edge.

  5. Selenium IDE, a Firefox extension that allows to record the tests, so you don't have to write them manually.

You can learn more about Selenium at their or read one of the interesting blog posts:

What is NUnit

NUnit is a testing framework that has great integration with Visual Studio as well as continuous integration systems (TeamCity, etc). We will use NUnit to run our Selenium tests.

NUnit provides a (command line and built into Visual Studio), to define the classes and functions that carry the testing code, that test the actual values.

Create a Test Project

It is recommended to keep the testing project in the same solution as the tested project. Note that they are two different projects.

In the following example, we will add acceptance tests to Launcher. Let's create a new test project in Visual Studio, by clicking Add New Project → Visual C# → Test → Unit Test Project.

Call the new project "Launcher.AcceptanceTest". We will use Launcher\test\ as the project location.

Install Required Packages

Open the newly created test project. Now, we need to install a bunch of libraries mentioned above.

Open the package manager (Tools → NuGet Packet Manager → Packet Manager Console).

Important: In the console, choose your test project from the "Default project" dropdown.

Run the following commands in the console to install the required dependencies:

Install-Package Selenium.WebDriver
Install-Package Selenium.Support
Install-Package NUnit
Install-Package NUnit.ConsoleRunner
Install-Package NUnit3TestAdapter

Running in Multiple Browsers

We don't want to test only Firefox. Because of that, you should use Selenium RemoteWebDriver, which adds a layer of abstraction that runs tests in multiple browsers, possibly on remote machines.

Install Selenium Standalone Server and Browser Drivers

To make this happen, you will need to install some additional software.

  • Download and install Java, required by Selenium Standalone Server

  • Create a directory C:\Selenium

    • Selenium Standalone Server (selenium-server-standalone-3.*.jar)

    • Gecko Driver (geckodriver.exe)

    • Microsoft Edge Driver (MicrosoftWebDriver.exe)

    • Google Chrome Driver (chromedriver.exe)

  • Put the jar file as well as 3 exe files directly in C:\Selenium

Open your Properties in the Tests project. Go to Reference Paths, enter C:\Selenium and click Add Folder.

Use BaseTest Class to Run Tests in Multiple Browsers

BaseTest is a helper class that makes it easier to test multiple browsers. The source code is available:

When you rebuild the test project now, you should see each test for every browser.

The final setup looks like this:

Before you can execute the tests, start Selenium Server Standalone by calling java -jar selenium-server-standalone-3.*.jar.

Wait for Asynchronous Content

There is one common pitfall when writing Selenium tests. The test is executed with disregard of the asynchronously loaded content. This means that your tests need to explicitly wait for UI elements to appear before running any actions or assertions on them.

It is a good practice to always wait:

  • Wait for a text element to be present before you check the content of that element

    • An example can be found in the method TextareaPage_WriteToTextArea in KitchenSink

      compare the text value of TextareaInfoLabel asynchronously. The assertion passes if the

      text is found within 5 seconds, otherwise it fails.

  • Wait for a button to be present before you click on that button

    • An example can be found in the method ButtonPage_RegularButton in the KitchenSink

      asynchronously check the state of the Displayed property of a button. It halts the test

      for a default maximum time of 10 seconds. If the button is not displayed within that

      time, it throws an exception.

  • Wait for presence of an input field before typing in it and wait for text to be present in label

    • An example can be found in the method TextPage_TextPropagationOnUnfocus in the

      presented above. The method WaitUntil() is used here to asynchronously wait for the

      input to be Displayed. Notice that the following response check is also done

      asynchrously using WaitForText.

Run the First Test

Build your test project. If it builds correctly, you should see this:

Now, the only thing left to do is to run that test! In the Test Explorer, click on the "Run All" button. If it works well, you should see your tests passing.

Sample Test Suites

Some of the Starcounter's sample apps come with acceptance test suite. We run tests every night to make sure that we keep the good quality.

You can learn more about NUnit at their or read one of the interesting blog posts:

Download the following files from :

BaseTest helper class

Using of BaseTest class

Tests (see ). The method WaitForText() is used to

tests (see ). The method WaitUntil() is used to

KitchenSink tests (see ). This test mixes the other examples

Clone from the on GitHub. Follow the steps that were presented at Install Selenium Standalone Server and browser drivers.

The sample app includes a Selenium test case for every UI pattern that is presented in that app. You can learn from the test project (in the test directory), how to achieve Selenium testing of particular actions, such as button clicks, page changing, typing in forms, etc.

The prefab app includes Selenium test of using Launcher with two mock applications (called "Launcher_AcceptanceHelperOne" and "Launcher_AcceptanceHelperTwo"). The test include executing JavaScript code on a page to scroll a DIV element and then checking the scroll position.

website (docs.seleniumhq.org)
Selenium Tutorial: Learn Selenium WebDriver
Getting Started with Selenium IDE
test runner
attributes
assertions
website (nunit.org)
C# Unit Test Tutorial
Unit testing with .NET
Learning NUnit In Easy Way For Beginners
Selenium Downloads
here
here
TextareaPageTest.cs lines 28-38
ButtonPageTest.cs lines 29-46
TextPageTest.cs lines 28-38
KitchenSink repo
StarcounterApps organisation
KitchenSink
Launcher