-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataDrivenTest.java
More file actions
43 lines (38 loc) · 1.31 KB
/
Copy pathDataDrivenTest.java
File metadata and controls
43 lines (38 loc) · 1.31 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Time;
import java.time.Duration;
import java.util.Set;
public class DataDrivenLogin {
WebDriver driver;
WebDriverWait wait;
@BeforeTest
public void setup() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
@Test
public void loginWithCSV() throws Exception {
driver.get("https://demoqa.com/login");
BufferedReader reader = new BufferedReader(new FileReader("data.csv"));
String line = reader.readLine();
while ((line = reader.readLine()) != null) {
String[] data = line.split(",");
WebElement user = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("userName")));
user.clear();
user.sendKeys(data[0]);
WebElement pass = driver.findElement(By.id("password"));
pass.clear();
pass.sendKeys(data[1]);
driver.findElement(By.id("login")).click();
Thread.sleep(2000);
driver.get("https://demoqa.com/login");
}
reader.close();
}
@AfterTest
public void tearDown() {
driver.quit();
}
}