在一个浏览器会话中运行某个功能的所有黄瓜方案 [英] running all cucumber scenarios for a feature in one browser session

查看:78
本文介绍了在一个浏览器会话中运行某个功能的所有黄瓜方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下功能,当一个场景完成执行时,我有2个场景,我希望cucumbe运行第二个场景。现在,当它完成执行一个场景时,它会打开浏览器的另一个线程而不执行第二个场景。我不想打开另一个线程,我想在单个浏览器线程中的第一个之后执行第二个场景。

I have below feature which have 2 scenarios when one scenario finish executing i want cucumbe to run 2nd scenario.Right now it when it finish executing one scenario it open another thread of browser and does not execute 2nd scenario. I dont want to open another thread, I want to execute the 2nd scenario after 1st in single browser thread.

功能:添加新联系人
作为用户,我想使用联系人链接插入新联系人

Feature: Add New Contact As a user, I want to insert new contact using Contacts link

方案概述:插入新联系人
给定用户单击联系人链接
当用户单击链接时创建新联系人
,用户输入名字为
,用户输入姓氏为
,用户输入电子邮件为
,用户输入代理商为
,用户单击保存按钮
,然后用户应看到消息联系人已成功保存。

Scenario Outline: Insert a New Contact Given user clicks on contacts link When user clicks on link Create New Contact And user enters first name as And user enters the last name as And user enters the Email as And user enters the Agency as And user click on save button Then user should see message "The contact was successfully saved."

  Examples:

  |first_name||last_name||email||Agency|
   |test2 |     |  test3       ||qa@incircuit.com||0000 - SURPLUS PROPERTY|

Scenario: create new user
        Given user clicks on create new user

下面是我的代码

public class insert_contact extends BasePage{
private static Initialize init;
private Insert_Contact contact=new Insert_Contact(driver);
public insert_contact(Initialize init) throws IOException {
    super(driver);
    init.Setup();
    init.getEnvironmentandCustomer();
}

@Given("^user clicks on contacts link$")
public void userClicksOnContactsLink() throws Throwable {
    contact.click_contacts_tab();
}
@When("^user clicks on link Create New Contact$")
public void userClicksOnLinkCreateNewContact() throws Throwable {

    contact.click_create_contact();
}

@And("^user enters first name as (.+)$")
public void userEntersFirstNameAsFirst_name(String fname) throws Throwable {
    contact.clickon_firstname();
    this.type(contact.first_name,fname);
}

@And("^user enters the last name as (.+)$")
public void userEntersTheLastNameAsLast_name(String lname) throws Throwable {
   contact.clickon_lastname();
   this.type(contact.last_name,lname);
}

@And("^user enters the Email as (.+)$")
public void userEntersTheEmailAsEmail(String email_address) throws Throwable {
    contact.cickon_email();
    this.type(contact.email,email_address);
}

@And("^user enters the Agency as (.+)$")
public void user_enters_Agency_as(String agency){
    contact.click_onAgency();
    this.type(contact.Agency,agency);
}

@And("^user click on save button$")
public void userClickOnSaveButton() throws Throwable {
   contact.clickon_Save();
}

@Then("^user should see message \"([^\"]*)\"$")
public void userShouldSeeMessage(String message) throws Throwable {
    Assert.assertEquals("The contact was successfully saved.",verifyTextPresent(By.id("success-message")));
}


@Given("^user clicks on create new user$")
public void userClicksOnCreateNewUser() throws Throwable {
    contact.click_onCreateNewUser();
}

}

推荐答案

对您问题的简单答案是,每个方案都会重新运行驱动程序创建代码,从而创建浏览器的新实例。我看不到@After方法,因此第一个方案创建的浏览器实例永远不会在其上运行quit()方法

The simple answer to your question is that each scenario reruns your driver creation code which creates a new instance of the browser. I don't see an @After method so the browser instance created by the first scenario never has the quit() method run on it thus leaving it open when the second scenario runs.

有两种一般的处理方法。

There are two general ways to handle this.


  1. 在@After方法中关闭(退出())浏览器实例,以便可以使用b在第二种情况开始时创建。

  1. Close (quit()) the browser instance in an @After method so that a fresh one can be created at the start of the second scenario.

对驱动程序的创建进行测试,并且仅当(driver == null)时创建一个新实例。 。然后,第二种情况将重用与第一种情况相同的浏览器会话。确保包含以下内容:

Have a test around the creation of your driver and only create a new instance if (driver == null). The second scenario will then reuse the same browser session as the first scenario. Be sure to include:

driver.manage()。deleteAllCookies();

driver.manage().deleteAllCookies();

这篇关于在一个浏览器会话中运行某个功能的所有黄瓜方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆