Огурец не может найти элемент - первый сценарий проходит, а последующие - нет - PullRequest
0 голосов
/ 10 апреля 2019

enter image description here Я запускаю тесты на огурец с селеном / TestNG и сообщаю через html. Первый сценарий проходит нормально, но последующие сбои, когда они должны проходить, из-за невозможности найти элемент. Второй сценарий (один неудачный) почти идентичен первому, он просто проверяет, отображается ли другой элемент на странице - что он определенно есть. Вот как выглядит мой файл функций:

Feature: LoginFeature
  This deals with logging in

  Scenario: Log in with correct username

    Given I navigate to the login page
    And I enter the following login details:
      | username | password |
      | cukey    | passwoid |
    And I click the login button
    Then I should land on the newest page

  Scenario: Log in with correct username part 2

    Given I navigate to the login page
    And I enter the following login details:
      | username | password |
      | cukey    | passwoid |
    And I click the login button
    Then I should land on the newest page by other measure

  Scenario: Log in with correct username to fail

    Given I navigate to the login page
    And I enter the following login details:
      | username | password |
      | cukey    | passwoid |
    And I click the login button
    Then I should land on the newest page wrongly

Вот мои определения / реализации шагов (@then с "отчеством" - это тот, который должен проходить):

package Steps;

import Base.BaseUtil;
import Pages.LoginPageObjeks;
//import cucumber.api.DataTable;
import io.cucumber.datatable.DataTable;
import cucumber.api.PendingException;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.ArrayList;
import java.util.List;


public class MaStepdefs extends BaseUtil {
    private BaseUtil base;

    public MaStepdefs(BaseUtil base) {
        this.base = base;
    }

    @And("^I click the login button$")
    public void iClickTheLoginButton() throws Throwable {
        LoginPageObjeks page = new LoginPageObjeks(base.Driver);
        page.ClickLogin();

    }

    @Given("^I navigate to the login page$")
    public void iNavigateToTheLoginPage() throws Throwable {

        base.Driver.navigate().to("http://www.executeautomation.com/demosite/Login.html");

    }

    @And("^I enter the following login details:$")
    public void iEnterTheFollowingLoginDetails(DataTable table) throws Throwable {

        List<List<String>> data = table.asLists(String.class);
        String userName = data.get(1).get(1);
        String passWord = data.get(1).get(0);

        List<User> users = new ArrayList();
        users.add(new User(userName, passWord));

        LoginPageObjeks page = new LoginPageObjeks(base.Driver);

        for (User user : users)
            page.Login(user.username, user.password);


        //List<User> users = new ArrayList<User>();

        //users = table.asList(User.class);




            Thread.sleep(2000);


        }

        @Then("^I should land on the newest page$")
        public void iShouldLandOnTheNewestPage () throws Throwable {
            Assert.assertEquals("It's not displayed", base.Driver.findElement(By.id("Initial")).isDisplayed(), true);
        }


    @Then("^I should land on the newest page wrongly$")
    public void iShouldLandOnTheNewestPageWrongly() throws Throwable {
        Assert.assertEquals("It's not displayed", base.Driver.findElement(By.id("fish")).isDisplayed(), true);
    }

    @Then("^I should land on the newest page by other measure$")
    public void iShouldLandOnTheNewestPageByOtherMeasure() throws Throwable {
        Assert.assertEquals("It's not displayed", base.Driver.findElement(By.id("Middle Name")).isDisplayed(), true);
    }

}

    class User {
        public String username;
        public String password;

        public User(String userName, String passWord) {
            username = userName;
            password = passWord;
        }
    }

А вот мой тестовый бегун:

package Runner;


import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

//@RunWith(Cucumber.class)
@CucumberOptions(features = {"src/test/java/features"}, plugin = {"json:target/cucumber.json", "html:target/site/cucumber-pretty"}, glue = "Steps")

public class TestRunner extends AbstractTestNGCucumberTests {
}

Кто-нибудь знает, что может быть причиной этого? Есть ли что-то, что мне нужно добавить для TestNG для запуска нескольких сценариев? Любая помощь будет оценена, спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...