【问题标题】:Is it possible, to call cucumber from a method in Selenium Java and TestNG?是否可以从 Selenium Java 和 TestNG 中的方法调用 cucumber?
【发布时间】:2020-08-06 14:52:27
【问题描述】:

我有一个工作系统,非常适合并行浏览器测试。 我可以做一个黄瓜场景效果很好的其他项目。不,我想把它们加在一起。我从脚本中复制了一些代码。我从 CLI 调用 @Test-s 与 TestNG 和 Maven 并行。 我写了一个新行“CALLTHECUCUMBERSCENARIO(driver);”我想在哪里调用 Cucumber Scenario。可能吗? 或者我该怎么做?任何想法? 如果有什么遗漏的让我现在,我把它写在这里。 谢谢您的帮助。 :)

@Test
    public void testChromeWin10() throws MalformedURLException, InterruptedException {
        String chromeNodeWin10 = "http://192.168.0.175:5566/wd/hub";
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("chrome");
        driver = new RemoteWebDriver(new URL(chromeNodeWin10), capabilities);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        Dimension d = new Dimension(1300,800);
        //Resize current window to the set dimension
        driver.manage().window().setSize(d);

        CALLTHECUCUMBERSCENARIO(driver);
    }


    @Test
    public void testFirefoxWin10() throws MalformedURLException, InterruptedException {
        String firefoxNodeWin10 = "http://192.168.0.175:5577/wd/hub";
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("firefox");
        driver = new RemoteWebDriver(new URL(firefoxNodeWin10), capabilities);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Dimension d = new Dimension(1300,1000);
        //Resize current window to the set dimension
        driver.manage().window().setSize(d);

        CALLTHECUCUMBERSCENARIO(driver);
    }


    @Test
    public void testEdgeWin10() throws MalformedURLException, InterruptedException {
        String edgeNodeWin10 = "http://192.168.0.175:5588/wd/hub";
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setBrowserName("MicrosoftEdge");
        driver = new RemoteWebDriver(new URL(edgeNodeWin10), capabilities);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Dimension d = new Dimension(1300,1000);
        //Resize current window to the set dimension
        driver.manage().window().setSize(d);

        CALLTHECUCUMBERSCENARIO(driver);

    }

【问题讨论】:

    标签: selenium cucumber cross-browser testng cucumber-jvm


    【解决方案1】:

    您不能按照您的要求从您的代码中调用 Cucumber 场景。

    您将不得不改变运行测试的方式。您可以使用 Cucumber runner 运行 Cucumber 场景,您可以在其中指定要运行的场景。

    要将 Cucumber 添加到您的项目中,请参阅 Cucumber docs - Installation

    Cucumber 的使用方法和跑步者的例子见Cucumber docs - 10 minute tutorial

    对于您迄今为止编写的测试,您需要将它们拆分为特征文件中有意义的步骤。一般来说,您的设置(安排)将在“给定”步骤中,您正在测试的操作(行为)在“时间”步骤中,您对预期结果的验证/验证(断言)在“那么”步骤中。

    您定义的每个步骤都将映射到一组(一组)操作/方法,这些操作/方法设置初始状态(Given)、执行测试(When)并验证结果(Then)。

    由您决定什么是有意义的步骤,以及如何在描述系统预期行为的场景/示例中描述它们。

    关于如何编写场景,请阅读:https://cucumber.io/docs/bdd/better-gherkin/

    关于如何实施,您可能会发现以下页面很有帮助: * https://cucumber.io/docs/gherkin/(特别是:https://cucumber.io/docs/gherkin/step-organization/) * https://cucumber.io/docs/cucumber/(特别是:https://cucumber.io/docs/cucumber/api/https://cucumber.io/docs/cucumber/step-definitions/

    你必须添加额外的设置才能跨浏览器运行它们(我没有这方面的经验,所以我无法帮助你)。

    【讨论】:

    • 谢谢,我以前可以这样做。不过谢谢你的帮助!
    猜你喜欢
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    相关资源
    最近更新 更多