-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.java
113 lines (104 loc) · 4.12 KB
/
test.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
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
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvValidationException;
import org.example.ConfProperties;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class test {
public WebDriver driver;
@Before
public void setup() {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(ConfProperties.getProperty("loginpage"));
}
@Test
public void CSVReader1by1() throws IOException, CsvValidationException {
WebElement formElement = driver.findElement(By.xpath("//input[@id]"));
List<WebElement> input = formElement.findElements(By.xpath("//input[@id]"));
CSVReader csvRead = new CSVReader(new FileReader("D:\\file.csv"));
String[] row = null;
try {
String[] data;
while ((data = csvRead.readNext()) != null) {
for (int a = 0; a < input.size(); a++) {
input.get(a).sendKeys(data[a]);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (CsvValidationException e) {
e.printStackTrace();
}
}
@Test
public void CSVReader1toall() throws IOException, CsvValidationException {
WebElement formElement = driver.findElement(By.xpath("//input[@id]"));
List<WebElement> input = formElement.findElements(By.xpath("//input[@id]"));
CSVReader csvRead = new CSVReader(new FileReader("D:\\file.csv"));
String[] row = null;
try {
String[] data;
while ((data = csvRead.readNext()) != null) {
for (int a = 0; a < input.size(); a++) {
input.get(a).sendKeys(data[0]);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (CsvValidationException e) {
e.printStackTrace();
}
}
@Test
public void CSVReaderallto1() throws IOException, CsvValidationException {
WebElement formElement = driver.findElement(By.xpath("//input[@id]"));
List<WebElement> input = formElement.findElements(By.xpath("//input[@id]"));
CSVReader csvRead = new CSVReader(new FileReader("D:\\file.csv"));
String[] row = null;
try {
String[] data;
while ((data = csvRead.readNext()) != null) {
for (int a = 0; a < input.size(); a++) {
input.get(0).sendKeys(data[a]);
input.get(0).clear();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (CsvValidationException e) {
e.printStackTrace();
}
}
@Test
public void CSVReaderalltoall() throws IOException, CsvValidationException {
WebElement formElement = driver.findElement(By.xpath("//input[@id]"));
List<WebElement> input = formElement.findElements(By.xpath("//input[@id]"));
CSVReader csvRead = new CSVReader(new FileReader("D:\\file.csv"));
String[] row = null;
try {
String[] data;
while ((data = csvRead.readNext()) != null) {
for (int a = 0; a < input.size(); a++) {
for (int b = 0; b < data.length; b++) {
input.get(a).sendKeys(data[b]);
Thread.sleep(1000);
input.get(a).clear(); }
}
}
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
}
}
}