-
Notifications
You must be signed in to change notification settings - Fork 0
/
signupautomation.java
96 lines (88 loc) · 3.23 KB
/
signupautomation.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
package testproject;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class signupautomation {
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 = "http://newtours.demoaut.com/mercuryregister.php?osCsid=f1719dfb1e1911dee56f22fdeaf8805c";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testAutomationsignuptestcase() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("REGISTER")).click();
driver.findElement(By.name("firstName")).clear();
driver.findElement(By.name("firstName")).sendKeys("akif");
driver.findElement(By.name("lastName")).clear();
driver.findElement(By.name("lastName")).sendKeys("hazarvi");
driver.findElement(By.name("phone")).clear();
driver.findElement(By.name("phone")).sendKeys("03446256500");
driver.findElement(By.id("userName")).clear();
driver.findElement(By.id("userName")).sendKeys("[email protected]");
driver.findElement(By.name("address1")).clear();
driver.findElement(By.name("address1")).sendKeys("xyz");
driver.findElement(By.name("address2")).clear();
driver.findElement(By.name("address2")).sendKeys("abc");
driver.findElement(By.name("city")).clear();
driver.findElement(By.name("city")).sendKeys("abc");
driver.findElement(By.name("state")).clear();
driver.findElement(By.name("state")).sendKeys("abc");
driver.findElement(By.name("postalCode")).clear();
driver.findElement(By.name("postalCode")).sendKeys("44000");
new Select(driver.findElement(By.name("country"))).selectByVisibleText("PAKISTAN");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("email")).sendKeys("akif");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("Ptcl@123");
driver.findElement(By.name("confirmPassword")).clear();
driver.findElement(By.name("confirmPassword")).sendKeys("Ptcl@123");
driver.findElement(By.name("register")).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;
}
}
}