获取cucumber.runtime.CucumberException:使用Testng运行cucmber脚本时无法加载插件类:prettty

时间:2018-04-19 02:50:58

标签: java maven selenium testng cucumber-java

您好我正在尝试运行使用带有testng的黄瓜开发的脚本但是我收到如下错误 - :

cucumber.runtime.CucumberException: Couldn't load plugin class: prettty
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:175)
    at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165)
    at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:226)
    at cucumber.runtime.formatter.PluginFactory.isFormatterName(PluginFactory.java:195)
    at cucumber.runtime.RuntimeOptionsFactory.addPlugins(RuntimeOptionsFactory.java:90)
    at cucumber.runtime.RuntimeOptionsFactory.buildArgsFromOptions(RuntimeOptionsFactory.java:37)
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:24)
    at cucumber.api.testng.TestNGCucumberRunner.<init>(TestNGCucumberRunner.java:37)
    at cucumber.api.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: prettty
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:173)
    ... 32 more

我的框架结构如下 - :

framework

我的pom文件如下 - :

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.w2a</groupId>
    <artifactId>CucumberPageObjects</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>1.1.0</version>
        </dependency>


    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe</executable>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>



            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <includes>
                        <exclude>**/*Demo.java</exclude>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.20</version>
            </plugin>


        </plugins>
    </build>
</project>

我的跑步者课程如下 - :

package runner;

import java.io.File;
import java.text.SimpleDateFormat;
impo

    rt java.util.Date;
    import java.util.HashMap;
    import java.util.Map;

    import org.testng.annotations.BeforeClass;

    import com.cucumber.listener.ExtentCucumberFormatter;

    import cucumber.api.CucumberOptions;
    import cucumber.api.testng.AbstractTestNGCucumberTests;




    @CucumberOptions(
            plugin= {"json:target/RunCuke/cucumber.json",
                    "prettty","html:target/RunCuke/cucumber.html",
                    "com.cucumber.listener.ExtentCucumberFormatter"},
            features="/src/test/resources/features",
            glue="steps",
            tags= {" @Search-Cars"}
            )
    public class RunCuke extends AbstractTestNGCucumberTests{

    @BeforeClass
    public static void setup() {
        SimpleDateFormat sdf=new SimpleDateFormat("ddMMyyyy_hhmmss");
        Date curdate=new Date();
        String strDate=sdf.format(curdate);
        String filename=System.getProperty("user.dir")+"\\target\\Exten_Report"+strDate +".html";
        File newFile=new File(filename);

        ExtentCucumberFormatter.initiateExtentCucumberFormatter(newFile,false);
        ExtentCucumberFormatter.loadConfig(new File("/src/test/resources/extent-config.xml"));


        ExtentCucumberFormatter.addSystemInfo("Browser Name","Chrome");
        ExtentCucumberFormatter.addSystemInfo("Browser Version","v57.0");
        ExtentCucumberFormatter.addSystemInfo("Selenium Version","v3.9.1");



        Map systemInfo=new HashMap();
        systemInfo.put("Cucumber version", "v1.2.3");
        systemInfo.put("Extent Cucumber  Report version", "v1.1.0");
        ExtentCucumberFormatter.addSystemInfo(systemInfo);







    }
    }


My utility class -:

package utils;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class SeleniumDriver {
    private static SeleniumDriver seleniumDriver;


    private static WebDriver driver;
    private static WebDriverWait waitdriver;
    public final static int timeout=30;
    public final static int pageloadtimeout=50;


    private SeleniumDriver() {
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/src/test/resources/executables/chromedriver.exe");
        driver=new ChromeDriver();
        driver.manage().window().maximize();

        waitdriver=new WebDriverWait(driver, timeout);
        driver.manage().timeouts().implicitlyWait(timeout   , TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(pageloadtimeout, TimeUnit.SECONDS);

    }

    public static void setupdriver() {
        if(seleniumDriver==null) {
            seleniumDriver=new SeleniumDriver();
        }
    }

    public static void tearDown() {

        if(driver!=null) {
            driver.close();
            driver.quit();
        }
        seleniumDriver=null;
    }

    public static void openpage(String url) {
        driver.get(url);
    }

    public static WebDriver getDriver() {
        return driver;
    }


}

我的步骤定义课程如下 - :

package steps;

import java.util.List;

import cucumber.api.PendingException;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import pages.actions.CarsGuideHomepageactions;
import pages.actions.CarsSearchpageactions;
import utils.SeleniumDriver;

public class SearchCarsSteps {

    CarsGuideHomepageactions homeactions=new CarsGuideHomepageactions();
    CarsSearchpageactions searchcar=new CarsSearchpageactions();


    @Given("^I am on the Home Page \"([^\"]*)\" of CarsGuide Website$")
    public void i_am_on_the_Home_Page_of_CarsGuide_Website(String url) throws Throwable {
        SeleniumDriver.openpage(url);
    }

    @When("^I move to Car For Sale Menu$")
    public void i_move_to_Car_For_Sale_Menu(List<String> list) throws Throwable {
        String menu=list.get(1);
        System.out.println("Menu selected is "+ menu);
        homeactions.movetocarsforsalemenu();
    }

    @And("^click on \"([^\"]*)\" link$")
    public void click_on_link(String searchcar) throws Throwable {
       homeactions.clickonsearchcars();
    }

    @And("^select carbrand as \"([^\"]*)\" from AnyMake dropdown$")
    public void select_carbrand_as_from_AnyMake_dropdown(String carbrand) throws Throwable {
        searchcar.selectcarmake(carbrand);
    }

    @And("^select \"([^\"]*)\" as car model$")
    public void select_as_car_model(String carmodel) throws Throwable {
        searchcar.selectcarmodel(carmodel);
    }

    @And("^select location as \"([^\"]*)\" from SelectLocation dropdown$")
    public void select_location_as_from_SelectLocation_dropdown(String loctn) throws Throwable {
        searchcar.selectcarlocation(loctn);
    }

    @And("^select \"([^\"]*)\" as price$")
    public void select_as_price(String price) throws Throwable {
        searchcar.selectcarprice(price);
    }

    @And("^click on Find_My_Next_Car button$")
    public void click_on_Find_My_Next_Car_button() throws Throwable {
        searchcar.clickonfindbutton();
    }

    @Then("^I should see list of searched cars$")
    public void i_should_see_list_of_searched_cars() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @And("^the page title should be \"([^\"]*)\"$")
    public void the_page_title_should_be(String arg1) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }



}

课前和课后 - :

package steps;

import cucumber.api.java.Before;
import utils.SeleniumDriver;

public class BeforeActions {

    @Before
    public static void setUp() {
        SeleniumDriver.setupdriver();
    }

}





package steps;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import cucumber.api.Scenario;
import cucumber.api.java.After;
import utils.SeleniumDriver;

public class Afteractions {

    @After
    public static void teardown(Scenario sc) {

        WebDriver driver =SeleniumDriver.getDriver();
        if(sc.isFailed()) {
            byte[] screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
            sc.embed(screenshot, "image/png");
        }
        SeleniumDriver.tearDown();
    }

}

功能文件如下 - :

@Search-Cars
Feature: Acceptance testing to validate Search Cars Page is working.
  In order to validate that 
  the Search Cars page is working
  Doing the Acceptance Testing

  @Search-Cars-Positive
  Scenario: Validate Search Cars Page
    Given I am on the Home Page "https://www.carsguide.com.au" of CarsGuide Website
    When I move to Car For Sale Menu
      | Menu          |
      | Cars For Sale |
    And click on "Search Cars" link
    And select carbrand as "BMW" from AnyMake dropdown
    And select "1 SERIES" as car model
    And select location as "Australia" from SelectLocation dropdown
    And select "$1,000" as price
    And click on Find_My_Next_Car button
    Then I should see list of searched cars
    And the page title should be "Bmw 1 Series Cars Under $1000 for Sale | CarsGuide"

我的extent-config.xml文件如下 - :

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
  <configuration>
    <!-- report theme -->
    <!-- standard, dark -->
    <theme>standard</theme>

    <!-- document encoding -->
    <!-- defaults to UTF-8 -->
    <encoding>UTF-8</encoding>

    <!-- protocol for script and stylesheets -->
    <!-- defaults to https -->
    <protocol>https</protocol>

    <!-- title of the document -->
    <documentTitle>ExtentReports by vikram</documentTitle>

    <!-- report name - displayed at top-nav -->
    <reportName>JUnit TestRunner : Cucumber Report by vikram</reportName>

    <!-- report headline - displayed at top-nav, after reportHeadline -->
    <reportHeadline></reportHeadline>

    <!-- global date format override -->
    <!-- defaults to yyyy-MM-dd -->
    <dateFormat>yyyy-MM-dd</dateFormat>

    <!-- global time format override -->
    <!-- defaults to HH:mm:ss -->
    <timeFormat>HH:mm:ss</timeFormat>

    <!-- custom javascript -->
    <scripts>
      <![CDATA[
        $(document).ready(function() {

        });
      ]]>
    </scripts>

    <!-- custom styles -->
    <styles>
      <![CDATA[

      ]]>
    </styles>
  </configuration>
</extentreports>

任何有助于解决此问题的帮助都受到高度尊重。 如果您需要我的代码的其他部分,请告诉我

1 个答案:

答案 0 :(得分:0)

你的跑步者400 bad request中的错字。应修改如下,这意味着您将在测试运行结束时获得一个不错的html报告。

'prettty'