Junit Runner不运行Cucumber功能

时间:2017-09-28 12:22:08

标签: selenium junit cucumber cucumber-junit selenide

当我调试它时,只有@BeforeClass配置工作 - 它打开浏览器并转到google.com,同样在控制台中我可以看到我的功能的场景,所以Runner看到它。所有人都说“测试被忽略”。如果我调试功能(不是通过Runner),它们可以工作。如何从我的Runner运行/调试它们(一次一个)?请帮我找错误

我的跑步者:

   package Runners;

   import com.codeborne.selenide.Configuration;
   import com.codeborne.selenide.WebDriverRunner;
   import cucumber.api.CucumberOptions;
   import cucumber.api.junit.Cucumber;
   import org.junit.BeforeClass;
   import org.junit.runner.RunWith;
   import org.openqa.selenium.WebDriver;

   import static com.codeborne.selenide.Selenide.open;
   import static com.codeborne.selenide.Selenide.sleep;


   @RunWith(Cucumber.class)
   @CucumberOptions(
    features = {"src/test/java/Features"},
    tags = {"@smokeTest#1"},
    glue = "src/test/java/Steps"

   )

   public class Runner {

       @BeforeClass
       static public void Initialization() {
           Configuration.timeout = 1500;
           Configuration.startMaximized = true;
           System.setProperty("webdriver.chrome.driver",                      
    "src\\test\\repository\\webDriver\\chromedriver.exe");
           Configuration.browser = "chrome";
           Configuration.savePageSource = false;
           Configuration.holdBrowserOpen = false;

           open("https://www.google.ru");


           Configuration.savePageSource = false;

       }


   }

2 个答案:

答案 0 :(得分:1)

愚蠢但快速的解决方法,创建一个像@WIP这样的新标签,并将其用于您唯一的场景。 要解决您的问题,请通过运行>>验证您的运行配置在IDE上运行配置

答案 1 :(得分:0)

根据@grasshopper在评论中建议,胶水选项应采用包格式。

E.g: 如果你的步骤定义直接在src / test / java / steps下,你应该使用:

@CucumberOptions(features = {"src/test/java/features"}, glue = {"your.package.steps"})

另一方面,如果你的步骤定义在多个包下(例如:src / test / java / your.package.steps),你应该有这样的东西:

import React from "react";
import {Meteor} from "meteor/meteor";
import {render} from "react-dom";
import {ApolloProvider} from "react-apollo";
import {ApolloLink, from} from "apollo-link";
import {ApolloClient} from "apollo-client";
import {HttpLink} from "apollo-link-http";
import {InMemoryCache} from "apollo-cache-inmemory";
import {onError} from 'apollo-link-error';
import {split} from 'apollo-link';
import {WebSocketLink} from 'apollo-link-ws';             //<======
import {getMainDefinition} from 'apollo-utilities';
import {toIdValue} from 'apollo-utilities';

import App from "../../ui/App";

// Create an http link:
const httpLink = new HttpLink({
    uri: Meteor.absoluteUrl("graphql"),
    credentials: 'same-origin'
})

// Create a WebSocket link:
const wsLink = new WebSocketLink({
    uri: `ws://localhost:3200/subscriptions`,
    options: {
        reconnect: true
    }
});

// using the ability to split links, you can send data to each link
// depending on what kind of operation is being sent
const splitLink = split(
    // split based on operation type
    ({query}) => {
        const {kind, operation} = getMainDefinition(query);
        return kind === 'OperationDefinition' && operation === 'subscription';
    },
    wsLink,
    httpLink,
);

const authLink = new ApolloLink((operation, forward) => {
    const token = Accounts._storedLoginToken();
    operation.setContext(() => ({
        headers: {
            "meteor-login-token": token
        }
    }));
    return forward(operation);
});


const client = new ApolloClient({
    link: ApolloLink.from([
        onError(({graphQLErrors, networkError}) => {
            if (graphQLErrors)
                graphQLErrors.map(({message, locations, path}) =>
                    console.log(
                        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
                    ),
                );
            if (networkError) console.log(`[Network error]: ${networkError}`);
        }),
        authLink,
        splitLink,
     ]),
    cache: new InMemoryCache({})
});

const ApolloApp = () => (
    <ApolloProvider client={client}>
        <App/>
    </ApolloProvider>
);

Meteor.startup(() => {
    render(<ApolloApp/>, document.getElementById("app"));
});