-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirefox.java
111 lines (104 loc) · 3.63 KB
/
Firefox.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
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.grid.internal.TestSession;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTRByReference;
public class Firefox {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private static User[] users;
@BeforeClass
public static void getUsers(){
users=Excel.getUserURL();
}
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://psych.liebes.top";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
private String deleteEndSlash(String url){
if(url.length()>0&&url.charAt(url.length()-1)=='/'){
url=url.substring(0,url.length()-1);
}return url;
}
public void testEach(User user)throws Exception{
driver.get(baseUrl + "/st");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(user.getUserName());
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(user.getPassword());
driver.findElement(By.id("submitButton")).click();
String urlOnWeb=driver.findElement(By.cssSelector("p.login-box-msg")).getText();
urlOnWeb=deleteEndSlash(urlOnWeb);
assertEquals(urlOnWeb.trim(), deleteEndSlash(user.getURL()).trim());
System.out.println(user.getUserName());
}
@Test
public void testAll()throws Exception{
for(int i=0;i<users.length;i++)if(users[i].getUserName().trim().length()>0){
testEach(users[i]);
}
}
public void testLab2() throws Exception {
driver.get(baseUrl + "/st");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("3015218088");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("218088");
driver.findElement(By.id("submitButton")).click();
System.out.println(driver.findElement(By.cssSelector("p.login-box-msg")).getText());
driver.get(baseUrl + "/st");
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("3015218050");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("218050");
driver.findElement(By.id("submitButton")).click();
System.out.println(driver.findElement(By.cssSelector("p.login-box-msg")).getText());
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}