编写自动测试以设置帐户的概念

时间:2018-04-03 19:57:20

标签: selenium testing automated-tests cucumber

我正在使用硒和黄瓜进行测试,我想知道将TestNG与黄瓜一起使用?当Cucumber,当TestNG?还是两个?

我有这样的示例场景:

  Scenario: Successful Create Account with Valid Credentials
    Given I am on Home Page
     When I Navigate to Create Account Page
      And I fill in "User Name" with <username>
      And I fill in "Password" with <password>
      And I fill in "Password" with <password>
      And I fill in "email" with <email>
     Then I see title "Congratulation you create account"
    Examples: 
      | username | password     | email          | 
      | Tom123   | password12   | Tom@gmailcom   | 
      | Kenny123 | fasfadfaadfa | Kenny@gmailcom |     

这是一个简单的确认测试,但是如果我想使用NastyString和很多组合测试我的帐户创建?

  Scenario: Unsuccessful reate Account with invalid Credentials
    Given I am on Home Page
     When I Navigate to Create Account Page
      And I fill in "UserName" with incorrect credentials 
     Then I see error message
      And I fill in "password" with incorrect credentials
     Then I see error message
      And I fill in "email" with incorrect credentials

这样的场景和使用带有BDD风格的数据提供程序的testNG进行测试?

4 个答案:

答案 0 :(得分:0)

在你的情况下你必须使用TestNG和Cucumber(两者一起)或JUnit和Cucumber我更喜欢JUnit。原因是TestNG创建Test Runner类会有点复杂。由于你的测试是作为黄瓜测试执行的,你可以使用JUnit或TestNG Runner来运行黄瓜类

跑步者类看起来像这样

    package cucumber;

import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)

@CucumberOptions(
glue={"stepDefinition"},
features = ("Feature"),
plugin = {"html:CucumberReports/cucumber-html-report"}
)
public class testRunner { }

所以你可以用JUnit来运行它(使用TestNG也会发生同样的事情) 因此,对于您的问题,您必须使用带有Junit的Cucumber和TestNG / Cucumber,并且必须使用JUnit / TestNG运行Runner类,同时将@Runwith注释设置为cucumber.class,如上例所示

如果您想使用JUnit的TestNG,这是一个可以使用的教程: https://medium.com/agile-vision/cucumber-bdd-part-2-creating-a-sample-java-project-with-cucumber-testng-and-maven-127a1053c180

答案 1 :(得分:0)

使用Cucumber进行这样的详尽测试会大大浪费您的时间和运行时间。

一般来说,编写良好的Cucumber场景至少比编写良好的单元测试慢一个数量级,所以如果你想进行详尽的测试,那么降低堆栈的测试是非常有益的。

此外,当您尝试在场景中指定所有内容时,Cucumber场景非常详细。大多数人所做的是使用大型复杂表格编写场景轮廓。这实现了创建大量慢速运行测试的双重否定,并使步骤定义更加复杂。在Cucumber中,你不能循环,当进行详尽的测试时,你必须指定每一个条件。这大大增加了变革的成本。

使用单元测试,您使用的是编程语言,因此您可以循环,映射和执行各种操作,以便以更少的工作量进行更多测试。

使用Cucumber擅长 - 描述行为和推动开发,而不是测试工具!!!

答案 2 :(得分:0)

你应该检查QAF-Gherkin QAF是建立在TestNG上进行黑盒测试的。您可以获得TestNG的所有功能,包括数据驱动功能,方法(场景)级并行执行等等。它也拥有自己的BDD实现。

答案 3 :(得分:0)

为什么不试试ginkgo4j?它使用Java 8 lambda来促进构建高度上下文的测试,就像你试图做的那样。上面的例子看起来有点像这样,例如: -

Describe("Successful Create Account with Valid Credentials", ()->{
  Context("Given I am on Home Page", () -> {
    BeforeEach({} -> {
      // java code to get home page
    });
    Context("When I Navigate to Create Account Page", () -> {
      BeforeEach({} -> {
        // java code to navigate to create account page
      });
      Context("And I fill in "User Name" with <username>", () -> {
        BeforeEach({} -> {
          // java code to enter username
        });
        Context("And I fill in "Password" with <password>", () -> {
          BeforeEach({} -> {
            // java code to enter password
          });
          Context("And I fill in "email" with <email>", () -> {
            BeforeEach({} -> {
              // java code to enter email
            });
            It("Then I see title "Congratulation you create account", () -> {
              // java code to click create button and assert success message
            });
          });
        });
      });
    });
  });
});

这样做的明显优势在于您永远不必离开Java。

相关问题