-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinstackTest.java
More file actions
154 lines (125 loc) · 7.33 KB
/
FinstackTest.java
File metadata and controls
154 lines (125 loc) · 7.33 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.browserstack;
import com.browserstack.SeleniumTest;
import org.openqa.selenium.By;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.browserstack.v2.utils.BrowserStack;
import org.openqa.selenium.JavascriptExecutor;
import com.browserstack.PercySDK;
public class FinstackTest extends SeleniumTest {
@Test
public void loginTest() throws Exception {
// --- Step 1: Navigate to the login page ---
System.out.println("Navigating to https://finstack-alpha.vercel.app/");
driver.get("https://finstack-alpha.vercel.app/");
try {
System.out.println("Attempting to maximize browser window...");
driver.manage().window().maximize();
System.out.println("Browser window maximized successfully.");
}
catch (org.openqa.selenium.UnsupportedCommandException e) {
System.out.println("Skipping maximize command: Command unsupported by the platform.");
}
BrowserStack.setCustomTag("ID", "TC-1294027");
Thread.sleep(1000);
PercySDK.screenshot(driver, "Before Login");
// --- Step 2: Input Email ---
String emailXPath = "//input[@id='email']";
System.out.println("Entering email: shrikrishna@browserstack.com");
driver.findElement(By.xpath(emailXPath)).sendKeys("shrikrishna@browserstack.com");
// --- Step 3: Input Password ---
String passwordXPath = "//input[@id='password']";
System.out.println("Entering password...");
driver.findElement(By.xpath(passwordXPath)).sendKeys("Test@123");
PercySDK.screenshot(driver, "After Filling Login Form");
// ====================================================================
// --- BROWSERSTACK SELF-HEALING DEMO LOGIC ---
// ====================================================================
// This is permanently set to true for this specific demo branch!
boolean triggerHeal = true;
if (triggerHeal) {
System.out.println("DEMO MODE: Clicking 'Enable' to change the UI from 'Sign In' to 'Login'.");
String enableButtonXPath = "//button[text()='Enable']";
driver.findElement(By.xpath(enableButtonXPath)).click();
Thread.sleep(5000); // Wait for the button text to change
}
// ====================================================================
// --- Step 4: Click Sign In Button ---
// BrowserStack knows this locator from the master branch runs.
// Here, it will fail (because we clicked Enable), and BrowserStack will heal it!
String signInButtonXPath = "//button[text()='Sign In']";
System.out.println("Clicking Sign In button using original locator...");
driver.findElement(By.xpath(signInButtonXPath)).click();
Thread.sleep(3000);
// --- Step 5: Assertion to verify successful login ---
System.out.println("Verifying successful login via dashboard element...");
Thread.sleep(2000);
String postLoginElementXPath = "//h1[contains(text(), 'Good morning')]";
boolean isLoginSuccessful = driver.findElement(By.xpath(postLoginElementXPath)).isDisplayed();
Assert.assertTrue(isLoginSuccessful, "Verification failed: Could not find the dashboard element after login.");
System.out.println("Login verification passed successfully!");
}
// The second @Test method for creating a new account (Unchanged from original).
@Test
public void createNewAccountAndVerifyProfile() throws Exception {
System.out.println("Navigating to https://finstack-alpha.vercel.app/");
driver.get("https://finstack-alpha.vercel.app/");
try {
System.out.println("Attempting to maximize browser window...");
driver.manage().window().maximize();
System.out.println("Browser window maximized successfully.");
}
catch (org.openqa.selenium.UnsupportedCommandException e) {
System.out.println("Skipping maximize command: Command unsupported by the platform.");
}
Thread.sleep(2000);
BrowserStack.setCustomTag("ID", "TC-1294020");
System.out.println("Clicking 'Create account' link.");
String createAccountLinkXPath = "//a[text()='Create account']";
driver.findElement(By.xpath(createAccountLinkXPath)).click();
Thread.sleep(2000);
System.out.println("Filling out the registration form.");
driver.findElement(By.xpath("//input[@id='firstName']")).sendKeys("John");
driver.findElement(By.xpath("//input[@id='lastName']")).sendKeys("Smith");
String randomEmail = "john.smith+" + System.currentTimeMillis() + "@example.com";
System.out.println("Using email: " + randomEmail);
driver.findElement(By.xpath("//input[@id='email']")).sendKeys(randomEmail);
driver.findElement(By.xpath("//input[@id='password']")).sendKeys("SamplePass123!");
driver.findElement(By.xpath("//input[@id='confirmPassword']")).sendKeys("SamplePass123!");
System.out.println("Clicking 'I agree to terms' checkbox.");
driver.findElement(By.xpath("//button[@id='agreeToTerms']")).click();
Thread.sleep(1000);
System.out.println("Clicking 'Create Account' button.");
driver.findElement(By.xpath("//button[text()='Create Account']")).click();
Thread.sleep(10000);
System.out.println("Clicking 'Collapse' button.");
String in_collapseButtonXPath = "//button[text()='Collapse']";
driver.findElement(By.xpath(in_collapseButtonXPath)).click();
Thread.sleep(1000);
System.out.println("Clicking 'Capture Image' button.");
driver.findElement(By.xpath("//button[normalize-space()='Capture Image']")).click();
Thread.sleep(2000);
System.out.println("Clicking 'Complete Verification' button.");
driver.findElement(By.xpath("//button[normalize-space()='Complete Verification']")).click();
System.out.println("Clicking 'Expand' button.");
driver.findElement(By.xpath("/html/body/div/div[1]/div[1]/div[2]/button")).click();
Thread.sleep(1000);
String currentUrl = driver.getCurrentUrl();
Assert.assertFalse(currentUrl.contains("signup"), "Verification failed: User is still on the signup page.");
System.out.println("Account creation successful. Current URL: " + currentUrl);
System.out.println("Clicking 'Collapse' button.");
String collapseButtonXPath = "//button[text()='Collapse']";
driver.findElement(By.xpath(collapseButtonXPath)).click();
Thread.sleep(1000);
System.out.println("Scrolling to the top of the page.");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollTo(0, 0);");
Thread.sleep(1000);
PercySDK.screenshot(driver, "Dashboard Top");
System.out.println("Verifying 'Good morning, John' is displayed on the page.");
String goodMorningTextXPath = "//h1[normalize-space(.)='Good morning, John']";
Assert.assertTrue(driver.findElement(By.xpath(goodMorningTextXPath)).isDisplayed(),
"Verification failed: 'Good morning, John' text is not displayed on the page.");
System.out.println("Successfully verified 'Good morning, John'. Test completed.");
}
}