Writing automated UI tests at a glance
This section describes the syntax of Protractor tests as well as the Page Object and Page Element design patterns, which are the best practices for the e2e testing. Armed with this knowledge, we will write a complete e2e test for the demo application introduced in Chapter 9, Miscellaneous Use Cases and Best Practices, in the section Displaying confirmation dialog with guarded routes.
Browser object, element, and locators
The browser object is a globally created wrapper around an instance of WebDriver
. It is used for navigation and page-wide information. With browser.get()
, you can navigate to a page and then check the page's title as follows:
describe('Google page', function() { it('should have a title', function() { browser.get('https://www.google.com'); expect(browser.getTitle()).toEqual('Google'); }); });
The current URL is returned by browser.getCurrentUrl()
. For example:
expect(browser.getCurrentUrl()).toContain('/admin');
Other global objects...