-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathLoginTest.java
68 lines (53 loc) · 2.26 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
package io.github.tahanima.e2e;
import static io.github.tahanima.util.DataProviderUtil.processTestData;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import io.github.tahanima.dto.LoginDto;
import io.github.tahanima.ui.page.ProductsPage;
import io.github.tahanima.util.TestRetry;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
/**
* @author tahanima
*/
public final class LoginTest extends BaseTest {
private static final String FILE_PATH = "login.csv";
@DataProvider(name = "loginData")
public Object[][] getLoginData(final Method testMethod) {
String testCaseId = testMethod.getAnnotation(Test.class).testName();
return processTestData(LoginDto.class, getTestDataFilePath(FILE_PATH), testCaseId);
}
@AfterMethod(alwaysRun = true)
public void captureScreenshotOnFailure(ITestResult result) {
ITestNGMethod method = result.getMethod();
if (ITestResult.FAILURE == result.getStatus()) {
loginPage.captureScreenshot(
String.format(
"%s_%s_%s",
method.getRealClass().getSimpleName(),
method.getMethodName(),
method.getParameterInvocationCount()));
}
}
@Test(
testName = "TC-1",
dataProvider = "loginData",
groups = {"smoke", "regression"},
retryAnalyzer = TestRetry.class)
public void testCorrectUserNameAndCorrectPassword(final LoginDto data) {
ProductsPage productsPage = loginPage.loginAs(data.getUsername(), data.getPassword());
assertThat(productsPage.getTitle()).isEqualTo("Products");
}
@Test(
testName = "TC-2",
dataProvider = "loginData",
groups = {"validation", "regression"},
retryAnalyzer = TestRetry.class)
public void testImproperCredentialsShouldGiveErrorMessage(final LoginDto data) {
loginPage.loginAs(data.getUsername(), data.getPassword());
assertThat(loginPage.getErrorMessage()).isEqualTo(data.getErrorMessage());
}
}