-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostHazard.java
More file actions
93 lines (85 loc) · 3.14 KB
/
PostHazard.java
File metadata and controls
93 lines (85 loc) · 3.14 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
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 PostHazard {
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 testPostHazard() throws Exception {
driver.get("http://csc648team07.herokuapp.com/");
driver.findElement(By.xpath("//a[contains(text(),'Sign\n in')]")).click();
driver.findElement(By.id("username")).click();
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("selenium");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("selenium");
driver.findElement(By.xpath("//button[@type='submit']")).click();
driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
new Select(driver.findElement(By.name("category"))).selectByVisibleText("Landslide");
driver.findElement(By.xpath("//option[@value='3']")).click();
driver.findElement(By.id("id_title_text")).click();
driver.findElement(By.id("id_title_text")).clear();
driver.findElement(By.id("id_title_text")).sendKeys("Landslide Hazard");
driver.findElement(By.id("id_content_text")).clear();
driver.findElement(By.id("id_content_text")).sendKeys("This is an automated Description written from Selenium.");
driver.findElement(By.id("autocomplete")).clear();
driver.findElement(By.id("autocomplete")).sendKeys("Daly City CA, USA");
driver.findElement(By.id("id_zipcode")).clear();
driver.findElement(By.id("id_zipcode")).sendKeys("94015");
driver.findElement(By.id("id_location")).clear();
driver.findElement(By.id("id_location")).sendKeys("Daly City");
driver.findElement(By.xpath("//button[@type='submit']")).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;
}
}
}