concept login page in category angular

This is an excerpt from Manning's book Angular Development with Typescript, Second Edition.
To manually test a specific workflow like the login functionality, a QA engineer prepares an ID/password that works, opens the login page, enters the ID/password, and clicks the Login button. After that, QA wants to assert that the landing page of your app is successfully rendered. The tester can also run another test to ensure that if the wrong ID/password is entered, the landing page won’t be rendered. This is a manual way of E2E testing of the login workflow.
The E2E test from the preceding section didn’t include a workflow that would require data entry and navigation. In this section, you’ll write a test for an app that uses a form and routing. The code that comes with this chapter includes a project called e2e-testing-samples with a simple app that has a login page and a home page. The routes in this app are configured in the following listing.
The first spec instructs Protractor to navigate to the login page and log in the user with the hardcoded data Joe and password. If the login was successful, the app navigates to the home page, and you assert this by checking that the URL in the browser contains /home. You also assert that the rendered page contains the header “Home Component.”
The spec for the failed login asserts that the app stays on the login page and the error message is displayed. Note in the following listing that this script has no code directly interacting with the UI.
Listing 14.24. login.e2e-spec.ts
import {LoginPage} from './login.po'; import {HomePage} from './home.po'; import {browser} from 'protractor'; describe('Login page', () => { let loginPage: LoginPage; let homePage: HomePage; beforeEach(() => { loginPage = new LoginPage(); #1 }); it('should navigate to login page and log in', () => { #2 loginPage.navigateToLogin(); #3 loginPage.login('Joe', 'password'); #4 const url = browser.getCurrentUrl(); #5 expect(url).toContain('/home'); #6 homePage = new HomePage(); #7 expect(homePage.getHeaderText()).toEqual('Home Component'); #8 }); it('should stay on login page if wrong credentials entered', () => { #9 loginPage.navigateToLogin(); loginPage.login('Joe', 'wrongpassword'); #10 const url = browser.getCurrentUrl(); expect(url).toContain('/login'); #11 expect(loginPage.getErrorMessage().isPresent()).toBe(true); #12 }); });