2017-08-29 76 views
0

我为我的主页编写了一些测试,但测试非常通用,如页脚,页眉检查。nightwatchjs,在多个页面上运行相同的测试

我的测试结构是这样的:

const footerCheck = function(browser){ 
    browser.url("example.com"); 
    browser.verify.elementPresent(".footer-top", "Footer-top is present.") 
    browser.verify.elementPresent(".footer-middle", "Legal notice bar is present") 
    browser.verify.elementPresent(".footer-bottom", "Copyright bar is present") 
    } 

export.module = { 
"Footer Check" : footerCheck 
} 

可以说我有100页。我想在所有页面上运行footerCheck函数。

网址像example.com/page1,example.com/page2,example.com/page3 ...

因为所有的测试是有效的其他网页,我想回路相同的测试的所有页面案例。不知怎的,我无法理解它。

这怎么可能,任何帮助将不胜感激。

感谢

+0

请提供更多示例代码,您的问题太笼统了。 –

+0

@BaoTran我已经更新了我的代码,希望它能给出一个想法。 – serkan

+0

我昨天在这里回答了一个类似的问题https://stackoverflow.com/questions/45988237/mocha-unable-to-run-with-nightwatch/46077141#46077141。如果你使用摩卡,你也可以创建动态测试,黄瓜也可以工作,但是它为你的测试增加了另外一层,如果你的团队不是全部使用BDD和黄瓜,它会伤害你的生产力。 – sonhu

回答

1

在我个人的经验,做BDD是增加使用gherkin语法黄瓜最好的方法。如果您知道如何使用它,它会更清晰并且有助于减少冗余代码。有一个Nightwatch npm plugin添加黄瓜,一旦你添加它,你必须创建类似如下

Feature: Check elements are present 
Scenario Outline: 
Given the user enters on a <page> 
Then .footer-top, .footer-middle and .footer-bottom class should be enabled 

Examples: 
|page| 
|page.com/page1| 
|page.com/page2| 
|page.com/page3| 

和你的步骤定义(在这里你声明一下将做的每一步)您.feature文件,它会自动将每个运行步骤为示例中提供的每个网址(请注意将在示例中替换的<page>标志,第一行是标记的名称)。

看一看examples

相关问题