Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginPageSteps extends BaseTest {
- public LoginPageSteps() throws Exception {
- super();
- }
- @Page
- LoginPage loginPage;
- @Given("^I am on login page$")
- public void goToLoginPage(){
- goTo(loginPage);
- }
- @When("^I enter username as '(.*?)'$")
- public void enterUsername(String username) {
- waitAndFill(loginPage.username, username);
- }
- @And("^I enter password as '(.*?)'$")
- public void enterPassword(String password) {
- waitAndFill(loginPage.password, password);
- waitUntilCliclableAndClick(loginPage.loginButton);
- }
- @Then("^Login should be succesfull$")
- public void checkLoginStatus() {
- assertTrue(getDriver().getCurrentUrl().contains("login_attempt=1"));
- }
- }
- public class BaseTest extends FluentCucumberTest {
- @Page
- AccountPage accountPage;
- @Before
- public void before(Scenario scenario) {
- super.before(scenario);
- }
- @After
- public void after(Scenario scenario) {
- super.after(scenario);
- }
- @Override
- public WebDriver newWebDriver() {
- System.setProperty("webdriver.gecko.driver", "../cucumber-test/src/test/resources/geckodriver.exe");
- FirefoxDriver driver = new FirefoxDriver();
- return driver;
- }
- public void waitUntilCliclableAndClick(FluentWebElement element) {
- await().atMost(5, TimeUnit.SECONDS).until(element).clickable();
- element.click();
- }
- public void waitAndFill(FluentWebElement element, String data) {
- await().atMost(5, TimeUnit.SECONDS).until(element).displayed();
- element.fill().with(data);
- }
- }
- Feature: valid-login
- Scenario:
- Given I am on login page
- When I enter username as "myusername"
- And I enter password as "mypassword"
- Then Login should be succesfull
- @RunWith(Cucumber.class)
- @CucumberOptions(features={"src/test/resources/features"})
- public class CucumberRunner {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement