AngularJS example MotoAds end-to-end tests
E2E (end-to-end) tests result: | Application folders tree: |
Recall
adverts.html
code which we should know to simulate user interaction:
Adverts
We should write the simple html page for running unit tests (
runner.html
):
When everything is ready we can start writing tests in
scenarios.js
.
Step 1
Navigate web browser to
index.html
which route to adverts.html
view:
'use strict'; describe('MotoAds App', function() { describe('Adverts view', function() { beforeEach(function() { browser().navigateTo('../../app/index.html#/'); }); // TEST WILL BE HERE }); }); ]]>
Step 2
We write first E2E test - filtering by brand and model on real data:
it('should filter on brand and model link click', function() { expect(repeater('.ma-advert-table-row').count()).toBe(29); element('.accordion-group:eq(0) ul:eq(0) a').click(); expect(repeater('.ma-advert-table-row').count()).toBe(4); element('.accordion-group:eq(3) ul:eq(0) a').click(); expect(repeater('.ma-advert-table-row').count()).toBe(2); }); ]]>
Step 3
We write second E2E test - filtering by country and region:
it('should filter on country and region select choose', function() { expect(repeater('.ma-advert-table-row').count()).toBe(29); select('filter.country').option('Germany'); expect(repeater('.ma-advert-table-row').count()).toBe(20); select('filter.region').option('Bavaria'); expect(repeater('.ma-advert-table-row').count()).toBe(18); }); ]]>
Step 4
We write third E2E test - filtering by year:
it('should filter on yearFrom and yearTo type', function() { expect(repeater('.ma-advert-table-row').count()).toBe(29); input('filter.yearFrom').enter('2010'); expect(repeater('.ma-advert-table-row').count()).toBe(16); input('filter.yearTo').enter('2011'); expect(repeater('.ma-advert-table-row').count()).toBe(14); }); ]]>
Step 5
We write fourth E2E test - sorting by year:
it('should sort by year', function() { expect(repeater('.ma-advert-table-row').count()).toBe(29); select('sortByCol').option("Year"); expect(element('.ma-advert-table-row:eq(0) td:eq(3)').text()).toContain('2005'); expect(element('.ma-advert-table-row:eq(28) td:eq(3)').text()).toContain('2012'); }); ]]>
Step 6
We run E2E test by typing in web browser URL
http://localhost:8000/test/e2e/runner.html
(motoAds application must be run on the web server). In web browser we should see the same as the screenshot E2E (end-to-end) tests result.
If you want to run this example on your computer, you can download sources from GitHub.
Any comment would be highly appreciated.
Komentarze