-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathLoginTest.java
79 lines (70 loc) · 2.55 KB
/
LoginTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package Tests;
import Pages.LoginPage;
import Tests.AbstractBaseTests.TestBase;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* Tests for a login page
*/
public class LoginTest extends TestBase {
private static final String LOGIN_SUCCESS_MESSAGE = "You are logged on as admin";
private static final String LOGIN_FAIL_MESSAGE = "You gave me the wrong username and password";
private static final String CORRECT_USER_NAME = "admin";
private static final String CORRECT_PASSWORD = "password";
private static final String FAIL_USER_NAME = "Wrong User";
private static final String FAIL_PASSWORD = "12345";
private static final String BAD_TEXT_ENTRY_MSG = "Username sent to text field incorrectly";
private LoginPage loginPage;
@Override
public String getName() {
return "Login Page";
}
/**
* Creates a login
*/
@BeforeTest
@Override
public void setUpPage() {
loginPage = new LoginPage(driver);
}
/**
* Tests logging in with valid credentials by verifying if the login message is correct
*/
@Test
public void loginSuccess() throws InterruptedException {
Assert.assertTrue(loginPage.login(CORRECT_USER_NAME, CORRECT_PASSWORD), BAD_TEXT_ENTRY_MSG);
Assert.assertEquals(loginPage.getMessage(), LOGIN_SUCCESS_MESSAGE);
}
/**
* Tests logging in with invalid credentials by verifying if the error message is correct
*/
@Test
public void loginFail() throws InterruptedException {
Assert.assertTrue(loginPage.login(FAIL_USER_NAME, FAIL_PASSWORD), BAD_TEXT_ENTRY_MSG);
Assert.assertEquals(loginPage.getMessage(), LOGIN_FAIL_MESSAGE);
}
/**
* After each test method, logout or try again
*/
@AfterMethod
public void logOut() {
loginPage.pressAltButton();
Assert.assertTrue(loginPage.checkIfBackAtLogin());
}
}