-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab2TestCase.java
84 lines (76 loc) · 2.54 KB
/
Lab2TestCase.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
package com.example.tests;
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.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class UntitledTestCase {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://www.katalon.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitledTestCase() throws Exception {
driver.get("http://121.193.130.195:8800/login");
driver.findElement(By.name("id")).click();
driver.findElement(By.name("id")).clear();
driver.findElement(By.name("id")).sendKeys("3016218083");
driver.findElement(By.name("password")).click();
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("218083");
driver.findElement(By.id("btn_login")).click();
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='LOG OUT'])[1]/following::h2[1]")).click();
driver.findElement(By.id("student-id")).click();
driver.findElement(By.id("student-git")).click();
driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalize-space(.)='LOG OUT'])[1]/preceding::span[3]")).click();
driver.findElement(By.id("btn_logout")).click();
driver.findElement(By.id("btn_return")).click();
}
@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;
}
}
}