gwen_test_structure

A .gwen file defines one or more tests, in which each test specifies the browsers that it will be run against. Each test starts with the following information:

  •  The name of the test
  • The URL where the test starts
  • The browsers that the rest will be run in
  • Optionally, to take screenshots after every statement
  • Where the test begins, and where the test ends

Example empty test

test "Reset Form"
url {base_url}/form1.html
browsers Chrome Firefox HtmlUnit Safari InternetExplorer
screenshots after each action
begin test
	# Your test statements go here
end test

Defining Multiple Tests

A single .gwen file can also define multiple test, for example:

test "My First Test"
url {base_url}/form1.html
browsers Chrome Firefox
begin test
	# Your test statements go here
end test

test "My Second Test"
url {base_url}/form1.html
browsers Chrome Firefox
begin test
	# Your test statements go here
end test

How does it work? See Form1Test.gwen

From the File menu select “Open Gwen Project” and select “examples/gwen”:

select_examples

 

The example project will load, which contains examples of how to interact with every HTML and Ext JS component:

example_project_load

The following test comes with the HTML5 Robot installation, and is used to test some basic data entry and popup window interactions in several different browsers:

test "Reset Form"
url {base_url}/form1.html
browsers Chrome Firefox HtmlUnit Safari
# We are skipping InternetExplorer because it takes forever
begin test
	wait to be clickable input by name "first"
	screenshot
	type "John" into input by name "first"
	type "Valentino" into input by name "last"
	assert that input by name "first" is "John"
	assert that input by name "last" is "Valentino"
	screenshot
	click button by text "Reset"
	assert that input by name "first" is ""
	assert that input by name "last" is ""
	screenshot
end test

test "Submit with Bad First Name"
url {base_url}/form1.html
browsers Chrome Firefox HtmlUnit Safari
# We are skipping InternetExplorer because it takes forever
begin test
	wait to be clickable input by name "first"
	screenshot
	type "Bad" into input by name "first"
	type "Lastname" into input by name "last"
	screenshot
	click button by text "Submit"
	assert that extjsdialog by default method contains "Invalid first name"
	screenshot
	click extjsdialogbutton by text "OK"
	wait to be clickable input by name "first"
	type "Bad" into input by name "first"
	assert that input by name "first" is "BadBad"
	screenshot
end test

You can execute a single file by right-clicking on it and selecting to run it:

rightclick_to_run

You can also select to run all tests by right-clicking on the project and selecting to run all:

run_all

The result of running Form1Test.gwen as that the following cases are executed

  • Reset Form in Chrome
  • Reset Form in Firefox
  • Reset Form in HtmlUnit
  • Reset Form in Safari
  • Submit with Bad First Name in Chrome
  • Submit with Bad First Name in Firefox
  • Submit with Bad First Name in HtmlUnit
  • Submit with Bad First Name in Safari

As the tests are being run you can see their progress in the browser and in the IDE:

runtime_example

When the test is over you are also given the option to see the detailed HTML Report, which can be seen here for Form1Test.gwen.

 

General IDE Operation

Creating a new Project

From the File menu select ” New Gwen Project”.

new_project

 

Next you will be asked to give your project a name, to select a directory to create the project inside, and to optionally give a base URL value that can be used as a shortcut inside your tests.

new_project_dialog

The result is an empty project workspace:

empty_workspace

Advanced Command Line Options

This section contains information on how to work with Gwen at the command-line.

Test Properties

Another important part of every test is the properties file, which specifies the locations of drivers, timeout settings, and optionally the base URL for where the test is located denoted by {base_url} in the .gwen file.

Available Properties:

  • build.directory – Specifies the location where the reports will be generated
  • chrome.driver – Specifies the location of the Chrome web driver
  • base.url – Specifies the value that will be injected into {base_url} for the url action in the test file
  • ie.driver – Specifies the location of the Internet Explorer web driver
  • default.timeout – Specifies how to long wait before failing any type of wait action

Example properties file:

build.directory=reports
chrome.driver=..\\..\\drivers\\chromedriver_win32_2.1\\chromedriver.exe
base.url=http\://html5robot.com/1.0/extjs
ie.driver=../drivers/IEDriverServer_Win32_2.35.3/IEDriverServer.exe
default.timeout=2

Running a Test File

An individual .gwen file can be run using the following command (assuming you have the location of the HTML5 Robot installation directory on your PATH environment variable):

gwen -properties "test.properties" -file "Form1Test.gwen"

The result is that each test in the given file is run in each of the browsers specified for that test.

For example if your .gwen file defines one test to be run in Chrome and Firefox, that test will be run once in Chrome and then once in Firefox.

The result of the test is both shown on the command line, and output to an HTML file with the same name as the .gwen file.

Running Multiple Test Files

All the .gwen files in a directory can be run using the following command:

gwen -properties "test.properties" -directory "."

The result is that each .gwen file is first evaluated, and after all files have been evaluated they are run one at a time.

For example if your directory has two Gwen files, each that contain 1 test, where each test is run in Chrome and Firefox the following will happen:

  • File #1 is evaluated
  • File #2 is evaluated
  • File #1 Test #1 is run in Chrome
  • File #1 Test #1 is run in Firefox
  • File #2 Test #1 is run in Chrome
  • File #2 Test #1 is run in Firefox

What next?

See Supported Browsers