Advertisement
Guest User

Untitled

a guest
May 10th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import static org.junit.Assert.assertEquals;
  2. import org.junit.AfterClass;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.WebDriver;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.chrome.ChromeDriver;
  9. import org.openqa.selenium.firefox.FirefoxDriver;
  10. import org.openqa.selenium.safari.SafariDriver;
  11. import org.openqa.selenium.support.ui.Select;
  12.  
  13. public class ZeroWebAppSecurity {
  14. public static WebDriver driver;
  15.  
  16. @Before
  17. public void setUp() throws Exception {
  18. //System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox Old\\firefox.exe");
  19. //System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
  20. driver = new SafariDriver();
  21. }
  22.  
  23. @Test
  24. public void test() throws InterruptedException {
  25. driver.get("http://zero.webappsecurity.com/");
  26.  
  27. WebElement signinBtn = driver.findElement(By.id("signin_button"));
  28. signinBtn.click();
  29.  
  30. // login
  31. WebElement username = driver.findElement(By.id("user_login"));
  32. username.sendKeys("username");
  33. WebElement password = driver.findElement(By.id("user_password"));
  34. password.sendKeys("password");
  35. password.submit();
  36.  
  37. // click pay bills
  38. WebElement payBillsLink = driver.findElement(By.linkText("Pay Bills"));
  39. payBillsLink.click();
  40.  
  41. // click Purchase Foreign Currency
  42. WebElement purchaseLink = driver.findElement(By.linkText("Purchase Foreign Currency"));
  43. purchaseLink.click();
  44.  
  45. // wait for the page to load, then select Canadian dollar
  46. Thread.sleep(500);
  47. Select currencySelect = new Select(driver.findElement(By.id("pc_currency")));
  48. currencySelect.selectByValue("CAD");
  49.  
  50. // enter amount
  51. WebElement amount = driver.findElement(By.id("pc_amount"));
  52. amount.sendKeys("100");
  53.  
  54. // select us dollars
  55. WebElement usDollars = driver.findElement(By.id("pc_inDollars_true"));
  56. usDollars.click();
  57.  
  58. // click the calculate costs button
  59. WebElement calcCostsBtn = driver.findElement(By.id("pc_calculate_costs"));
  60. calcCostsBtn.click();
  61.  
  62. // wait for the calculation
  63. Thread.sleep(250);
  64.  
  65. // assert test
  66. WebElement resultLabel = driver.findElement(By.id("pc_conversion_amount"));
  67. assertEquals(resultLabel.getText(), "94.19 dollar (CAD) = 100.00 U.S. dollar (USD)");
  68. }
  69.  
  70. @AfterClass
  71. public static void afterClass() {
  72. // closes the browser
  73. driver.quit();
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement