sandeshp7

TestSteps.java

Aug 2nd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package stepDefinition;
  2.  
  3. import static org.junit.Assert.assertTrue;
  4.  
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import org.openqa.selenium.By;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.chrome.ChromeDriver;
  10.  
  11. import cucumber.api.java.After;
  12. import cucumber.api.java.Before;
  13. import cucumber.api.java.en.Given;
  14. import cucumber.api.java.en.Then;
  15. import cucumber.api.java.en.When;
  16.  
  17. public class TestSteps {
  18.  
  19.     public static WebDriver driver;
  20.    
  21.     //This will run before every test. This is not a JUnit Before. it is Cucumber's
  22.     @Before
  23.     public void beforeTest() {
  24.         driver = new ChromeDriver();
  25.         driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
  26.         driver.manage().deleteAllCookies();
  27.         driver.manage().window().maximize();
  28.     }
  29.    
  30.     //This will run after every test. This is not a JUnit After. it is Cucumber's
  31.     @After
  32.     public void afterTest() {
  33.         driver.close();
  34.     }
  35.    
  36.     //each method directly maps to the feature file
  37.     @Given("^User is on Google Search Landing Page$")
  38.     public void user_is_on_Google_Search_Landing_Page() throws Throwable {
  39.         driver.get("https://www.google.co.uk/");
  40.     }
  41.  
  42.     @When("^User enters a search string$")
  43.     public void user_enters_a_search_string() throws Throwable {
  44.         driver.findElement(By.id("lst-ib")).sendKeys("Cucumber Test Framework");
  45.     }
  46.  
  47.     @When("^clicks on search button$")
  48.     public void clicks_on_search_button() throws Throwable {
  49.         driver.findElement(By.id("sblsbb")).click();
  50.     }
  51.  
  52.     @Then("^Search result is displayed$")
  53.     public void search_result_is_displayed() throws Throwable {
  54.         assertTrue(driver.findElement(By.linkText("Cucumber")).isDisplayed());
  55.     }
  56. }
Add Comment
Please, Sign In to add comment