A simple spec file may look like this:
The output would be: Bird flies way
For further simple examples, have a look at this Simple Protractor Example
Real world example
After a simple example here's on from the Random Page plugin (source adminSection.spec.js). It follows the same structure as the bird example.
There are some more import than one object, the import include external resources (e.g. Confluence Protractor Base) and internal ones (e.g. RandomPageAdministration)
'describe blocks' always declare the objects (or sometimes the methods) to be tested, as you see they can be nested. In this case it tests the PagesLimit property inside the Random Page administration page.
'it blocks' label the actual test cases. The 'it' refers to the surrounding object from the describe block. As you know from other tes
The actual test
The test case should follow the structure 'given - when - then'. 'expect' is similiar to 'assert' in junit. 'toBe' defines a jasmine matcher that compares the result and expected values.
Have a look at the build in jasmine matchers.
Before and after
For functions that should be executed right before all tests of the surrounding describe block you can define "beforeAll" (similar to @setup in junit). The same thing can be done after all tests with 'afterAll'. If there are thing that should be done before or after every test case (beforeEach and afterEach).
In this example we first authenticate as admin (login and administrator access confirmation).
You now know the structure of a spec file and the elements for writing your own test. We recommend to start with something simple (an admin sections is such a thing). Write the structure and simply check if an element exists or has the expected value. For an easier start, have a look at already written specs in the Random Page app or the Confluence Protractor Base.
- No labels