Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. public class LoginPageSteps extends BaseTest {
  2.  
  3. public LoginPageSteps() throws Exception {
  4. super();
  5. }
  6.  
  7. @Page
  8. LoginPage loginPage;
  9.  
  10.  
  11. @Given("^I am on login page$")
  12. public void goToLoginPage(){
  13. goTo(loginPage);
  14. }
  15.  
  16. @When("^I enter username as '(.*?)'$")
  17. public void enterUsername(String username) {
  18. waitAndFill(loginPage.username, username);
  19. }
  20.  
  21. @And("^I enter password as '(.*?)'$")
  22. public void enterPassword(String password) {
  23.  
  24. waitAndFill(loginPage.password, password);
  25. waitUntilCliclableAndClick(loginPage.loginButton);
  26.  
  27. }
  28.  
  29. @Then("^Login should be succesfull$")
  30. public void checkLoginStatus() {
  31. assertTrue(getDriver().getCurrentUrl().contains("login_attempt=1"));
  32.  
  33. }
  34. }
  35.  
  36. public class BaseTest extends FluentCucumberTest {
  37.  
  38. @Page
  39. AccountPage accountPage;
  40.  
  41.  
  42. @Before
  43. public void before(Scenario scenario) {
  44. super.before(scenario);
  45. }
  46.  
  47. @After
  48. public void after(Scenario scenario) {
  49. super.after(scenario);
  50. }
  51.  
  52. @Override
  53. public WebDriver newWebDriver() {
  54.  
  55. System.setProperty("webdriver.gecko.driver", "../cucumber-test/src/test/resources/geckodriver.exe");
  56. FirefoxDriver driver = new FirefoxDriver();
  57.  
  58. return driver;
  59. }
  60.  
  61. public void waitUntilCliclableAndClick(FluentWebElement element) {
  62. await().atMost(5, TimeUnit.SECONDS).until(element).clickable();
  63. element.click();
  64. }
  65.  
  66. public void waitAndFill(FluentWebElement element, String data) {
  67. await().atMost(5, TimeUnit.SECONDS).until(element).displayed();
  68. element.fill().with(data);
  69. }
  70.  
  71.  
  72.  
  73. }
  74.  
  75. Feature: valid-login
  76.  
  77. Scenario:
  78. Given I am on login page
  79. When I enter username as "myusername"
  80. And I enter password as "mypassword"
  81. Then Login should be succesfull
  82.  
  83. @RunWith(Cucumber.class)
  84. @CucumberOptions(features={"src/test/resources/features"})
  85. public class CucumberRunner {
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement