在Cucumber特征文件中使用“背景”时无根错误的测试错误

时间:2015-06-15 17:33:10

标签: selenium cucumber

我是Selenium的新手并且练习黄瓜。我正在做一个示例项目,我在其中创建了一个“CreateLead”测试。当我在功能文件中不使用“背景:”时,使用Junit成功执行测试。

如果我在功能文件中包含“背景:”,我将面临“无根测试”异常。有人可以帮我解决这个问题吗?

CreateLead功能文件

Feature: Creating Lead

In order to get more revenue 
As a sales person 
I want to create leads

Background:
Given I am logged in salesforce in Mozilla
Given I am logged in salesforce in Chrome

@CreateLead
Scenario Outline: Creating Leads
Given Browser is "<Browser>"
And I click on the tab "LeadTab"
And I click on the button "NewLeadButton"

Examples:
  |Browser  |
  |Mozilla  |
  |Chrome   |

CreateLeadTest

package com.qtpselenium.CreateLeadTestCase;

import org.junit.Assert;

import com.qtpselenium.util.Webconnector;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;

public class CreateLeadTest {
    Webconnector Selenium= Webconnector.getInstance();

    @Given("^I am logged in salesforce in \"([^\"]*)\"$")
    public void I_am_logged_in_salesforce(String browser) throws Throwable{
    Selenium.openBrowser(browser);
    Assert.assertTrue("Not logged in", Selenium.isLoggedIn());
    }

    @Given("^Browser is \"([^\"]*)\"$")
    public void Browser_is(String browser) throws Throwable{
        Selenium.openBrowser(browser);
        Selenium.isLoggedIn();
    }

    @And("^I click on the tab \"([^\"]*)\"$")
    public void I_click_on_the_tab(String object)throws Throwable{
        Selenium.click(object);
    }

    @And("^I click on the button \"([^\"]*)\"$")
    public void I_click_on_the_button(String object)throws Throwable{
        Selenium.click(object);
    }

错误: 无根测试 - @Ignore:鉴于我在Mozilla中登录了Salesforce @Ignore:鉴于我在Chrome中登录了Salesforce

1 个答案:

答案 0 :(得分:0)

背景 场景 之前开始运行,并以 Hooks 结束。

尝试从后台删除“鉴于我在Chrome中登录salesforce”并执行测试。这意味着我们的目标是在Mozilla中为此实例运行测试。

我确信测试成功执行