Огурец не работает селен код

Когда я пытаюсь запустить свой код, он показывает только скелет огурца. Я использую класс бегунов JUnit как набор тестов JUnit.

Код ниже для всех трех классов.

Особенность:

Feature: Check addition in Google calculator

   In order to verify that google calculator work correctly
   As a user of google
   I should be able to get correct addition result
@Runme
   Scenario: Addition
   Given I open google
   When I enter "2+2" in search textbox
   Then I should get result as "4"

Селен Класс:

package cucumberTest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumTest {
    private SeleniumTest()
    {


    }
        private static WebDriver driver = null;
    public static void seleniumTest() {
        // Create a new instance of the Firefox driver

        driver = new FirefoxDriver();

        //Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        //Launch the Online Store Website

        driver.get("http://www.store.demoqa.com");

        // Find the element that's ID attribute is 'account'(My Account) 

        driver.findElement(By.xpath(".//*[@id='account']/a")).click();

        // Find the element that's ID attribute is 'log' (Username)

        // Enter Username on the element found by above desc.

        driver.findElement(By.id("log")).sendKeys("testuser_1"); 

        // Find the element that's ID attribute is 'pwd' (Password)

        // Enter Password on the element found by the above desc.

        driver.findElement(By.id("pwd")).sendKeys("Test@123");

        // Now submit the form. WebDriver will find the form for us from the element 

        driver.findElement(By.id("login")).click();

        // Print a Log In message to the screen

        System.out.println("Login Successfully");

        // Find the element that's ID attribute is 'account_logout' (Log Out)

        driver.findElement (By.xpath(".//*[@id='account_logout']/a")).click();

        // Print a Log In message to the screen

        System.out.println("LogOut Successfully");

        // Close the driver

        driver.quit();

    }

}

Класс JUnit:

package cucumberTest;

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

@RunWith(Cucumber.class)
//@CucumberOptions(
    //  features = "Feature/googleCalc.feature"
        ////,glue={"stepDefinition"}
    //  )
@CucumberOptions(

features = {"Feature/googleCalc.feature"},glue={"stepDefinition"},

plugin = {"pretty"},

tags = {"@Runme"}

)

public class TestRunner {

}

Определения шагов:

package stepDefination;


import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumberTest.SeleniumTest;

public class googleCalcStepDefinition {

    @Given("^I open google$")
    public void i_open_google() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
      SeleniumTest.seleniumTest();
    }

    @When("^I enter \"(.*?)\" in search textbox$")
    public void i_enter_in_search_textbox(String arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        SeleniumTest.seleniumTest();
    }

    @Then("^I should get result as \"(.*?)\"$")
    public void i_should_get_result_as(String arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        SeleniumTest.seleniumTest();
    }

}

Показанный результат:

Feature: Check addition in Google calculator

   In order to verify that google calculator work correctly
   As a user of google
   I should be able to get correct addition result

  @Runme
  Scenario: Addition                     [90m# Feature/googleCalc.feature:7[0m
    [33mGiven [0m[33mI open google[0m
    [33mWhen [0m[33mI enter "2+2" in search textbox[0m
    [33mThen [0m[33mI should get result as "4"[0m

1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^I open google$")
public void i_open_google() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I enter \"(.*?)\" in search textbox$")
public void i_enter_in_search_textbox(String arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should get result as \"(.*?)\"$")
public void i_should_get_result_as(String arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

1 ответ

Я нашел причину, по которой это не выполнялось, потому что я добавил тестовый класс Selenium и класс бегуна Junit в Package cucumberTest; и скелет был в пакете stepDefination; поэтому я переместил скелет в pacakge cucumberTest; где Junit Runner и Selen классы это решило проблему для. Произошла ошибка, потому что когда вы помещаете класс Junit в пакет, он будет искать скелет в этом пакете, но если вы добавите класс бегуна JUnit в исходную папку, он сможет найти страницу в папке src

Другие вопросы по тегам