Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. package org.ucll.demo.service;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Statement;
  6. import java.util.Properties;
  7.  
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.WebDriver;
  10. import org.openqa.selenium.WebElement;
  11. import org.openqa.selenium.firefox.FirefoxDriver;
  12.  
  13. import cucumber.api.java.After;
  14. import cucumber.api.java.Before;
  15. import cucumber.api.java.en.Given;
  16. import cucumber.api.java.en.Then;
  17. import cucumber.api.java.en.When;
  18. import junit.framework.Assert;
  19.  
  20. public class SmokeDetailsSteps {
  21. private WebDriver driver;
  22.  
  23. @Before
  24. public void setUp() {
  25. driver = new FirefoxDriver();
  26. }
  27.  
  28. @After
  29. public void tearDown() {
  30. Properties properties = new Properties();
  31. String url = "jdbc:postgresql://gegevensbanken.khleuven.be:51617/lector";
  32. properties.setProperty("user", "u0082726");
  33. properties.setProperty("password", "mySecret");
  34. properties.setProperty("ssl", "true");
  35. properties.setProperty("sslfactory", "org.pastgresql.ssl.NonValidatingFactory");
  36.  
  37. Connection connection;
  38. try {
  39. connection = DriverManager.getConnection(url, properties);
  40. Statement statement = connection.createStatement();
  41. String sql ="DELETE FROM u0082726.users WHERE userid = Jakke ";
  42. statement.execute(sql);
  43. } catch (Exception e) {
  44.  
  45. e.printStackTrace();
  46. }
  47. driver.close();
  48. }
  49.  
  50. private void fillOutField(String id, String keys) {
  51. WebElement field = driver.findElement(By.id(id));
  52. field.sendKeys(keys);
  53. }
  54.  
  55. @Given("^I am registered with userid Jakke and password TopSecret$")
  56. public void i_am_registered_with_userid_Jakke_and_password_TopSecret() throws Throwable {
  57. driver.get("http://java.cyclone2.khleuven.be:38034/shop-web-demo/Controller?action=signUp");
  58. fillOutField("userid", "Jakke");
  59. fillOutField("firstName", "Jakke");
  60. fillOutField("lastName", "Fictie");
  61. fillOutField("email", "Jakke.Fictie@fictie.com");
  62. fillOutField("password", "TopSecret");
  63.  
  64. WebElement button = driver.findElement(By.id("signUp"));
  65. button.click();
  66. }
  67.  
  68. @When("^I log in with my username and password$")
  69. public void i_log_in_with_my_username_and_password() throws Throwable {
  70. driver.get("http://java.cyclone2.khleuven.be:38034/shop-web-demo/Controller?action=signUp");
  71. fillOutField("userId", "Jakke");
  72. fillOutField("password", "TopSecret");
  73. WebElement button = driver.findElement(By.id("logIn"));
  74. button.click();
  75. }
  76.  
  77. @Then("^I am redirected to the welcome page$")
  78. public void i_am_redirected_to_the_welcome_page() throws Throwable {
  79. boolean currentpage = driver.findElement(By.cssSelector("p")).getText().equals("Welcome Jakke!");
  80. Assert.assertTrue(currentpage);
  81. }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement