-
Notifications
You must be signed in to change notification settings - Fork 0
/
US3S4AddDeployKey.java
104 lines (93 loc) · 4.17 KB
/
US3S4AddDeployKey.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
//Test for US-3 Scenario-4
//Tests that user can add a deploy key to their repo
//Notes:
//Key used is a non used 'dummy' key generated by me
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 US3S4AddDeployKey {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
//Hardcoded auth for 'permenent' user. Hopefully a bot doesn't steal this account.
private static final String USERNAME = "cs1632user";
private static final String PASSWORD = "cs1632pass";
//Utility function
private void logIn(String username, String password) {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Sign in")).click();
driver.findElement(By.id("login_field")).clear();
driver.findElement(By.id("login_field")).sendKeys(username);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.name("commit")).click();
}
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://github.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
logIn(USERNAME, PASSWORD); //login
}
@Test
public void testUS3S4AddDeployKey() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("newrepo")).click();
driver.findElement(By.xpath("(//a[contains(@href, '/cs1632user/newrepo/settings')])[2]")).click();
driver.findElement(By.linkText("Deploy keys")).click();
driver.findElement(By.linkText("Add deploy key")).click();
assertTrue(isElementPresent(By.id("public_key_read_only")));
driver.findElement(By.id("public_key_title")).clear();
driver.findElement(By.id("public_key_title")).sendKeys("fake key");
driver.findElement(By.id("public_key_key")).clear();
driver.findElement(By.id("public_key_key")).sendKeys("ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAvWeozCoQ3jFsiRKmcSvHa9C9HUxCT94r/kZIR3YLiz6QAoaWvZpkb1UZ+Al+1bAkObcNsTeuR+gm+HZQ2jvPHm0WYlt7VTwykWP7wt4faWitcvlEXsOxme7KpzGLf8P7LbE19vpixIBXxWBeURwQY74ufNrZ67tFOgvhEvmNRQx8hvz72GzwhF/OowGBHWhPWfNcsv8LPcYgXdbyb66STh+6Vd7tBuSwXfLXq3ifwgP2DfkDF+uu+nxfsmmfHNixj5KboHsCBrbBfMZCY9qjY1v07+dV3O8/8iDf65zmcSJVACLBrV82WqvRRvJoE7vZSk/mv5V8haF/YeWVSLDr1F/JYbqFrJM9RfUmQsk4wviYMF6US1edNybiKAxot1ASOfdPSy1JzrLHuhtl6+9OIIz5mkGkO9ox5Ei8GcJI8Ht8FFOoj31iqoOwsV3MJk/OPIapF7OFMHW0wa6VTS1eqHhyJtIAFZ/V5uYC7iKBJ6KYuSTbrtTnoMO0lHQ0vD+PtAqxRK7Y15TPb/pSz/VRKAXcpitqlVF0DHZaZazXLFZQ9Yp8/DNg/uskgQdEpTCKvrFi0gGkEbwxArESuq/FqsIEKbdnggDI2sWdoWku5lqHNggAqUwAl3NHo6NoIVMfjZvMm5QhqmVC7caUd2DJlZ0F7luaDnrlheVxPxYJ6gE= graphitezeppelin@gmail.com");
driver.findElement(By.cssSelector("button.btn.btn-primary")).click();
assertEquals("fake key", driver.findElement(By.cssSelector("strong.ssh-key-title")).getText());
assertTrue(isElementPresent(By.cssSelector("span.mega-octicon.octicon-key")));
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;
}
}
}