首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >几个Webdriver IO Mocha Chai问题

几个Webdriver IO Mocha Chai问题
EN

Stack Overflow用户
提问于 2016-08-24 09:48:16
回答 1查看 346关注 0票数 0

我不熟悉在Mocha和Chai中使用webdriver-io。首先,这是我的脚本:

代码语言:javascript
复制
var homePage = 'http://www.mypage.com';
var expect = require("chai").expect;
var headerText = 'h1.browse-header-title';
var currentHeaderText;
var links = ['Furniture','Fine Art','Jewelry & Watches','Fashion'];

describe('Test Suite 1', function(){

    before(function(){
       console.log('Running navigation h1 tag suite');
    });

    afterEach(function(){
        browser.close();
        // What method do I use?
    });

    it('Should click Furniture and page header should match', function(done){
       browser.url(homePage).click('a[data-tn="global-nav-item-link-furniture"]');
        currentHeaderText = browser.getText(headerText);
        expect(currentHeaderText).to.equal(links[0]);
        console.log('h1 tag is '+currentHeaderText+'');
    });
    it('Should click Fine Art and page header should match', function(done){
        browser.url(homePage).click('a[data-tn="global-nav-item-link-fine-art"]');
        currentHeaderText = browser.getText(headerText);
        expect(currentHeaderText).to.equal(links[1]);
        console.log('h1 tag is '+currentHeaderText+'');

    });
    it('Should click Jewelry & Watches and page header should match', function(done){
        browser.url(homePage).click('a[data-tn="global-nav-item-link-jewelry-&-watches"]');
        currentHeaderText = browser.getText(headerText);
        expect(currentHeaderText).to.equal(links[2]);
        console.log('h1 tag is '+currentHeaderText+'');
    });
    it('Should click Fashion and page header should match', function(done){
        browser.url(homePage).click('a[data-tn="global-nav-item-link-fashion"]');
        currentHeaderText = browser.getText(headerText);
        expect(currentHeaderText).to.equal(links[3]);
        console.log('h1 tag is '+currentHeaderText+'');
    });

});

我的第一个问题是,有没有更好的地方存储变量和调用它们的适当方法?

在运行afterEach browser.close()函数时,重置浏览器会话的最佳方法是什么?我尝试了browser.reset(),但在调用第二个测试时,它似乎不能正常工作。使用mocha和chai有没有更好的方法来关闭浏览器,重置会话,打开浏览器并转到主页?

以下是我得到的要求:

1)测试必须用mocha编写,并使用chai进行断言。用于驱动测试的框架必须是webdriverIO -没有本机selenium命令。

2)测试应该以一种利用页面对象模式的方式编写

3)可能在其他测试中使用的变量(如用户电子邮件/密码)应与测试文件分开存储。

EN

回答 1

Stack Overflow用户

发布于 2016-08-31 09:26:11

要在代码之外存储变量,有几种方法。

  1. 您可以利用wdio.conf.js并开始添加customConfig对象,如this,并在代码_page.navigate(browser.options.customConfig.baseUrl);中使用它们,如this
  2. Or,将其保存在单独的.json文件中,使用nconf在测试代码中引入测试数据,或简单地导入data.json,如从'./testdata.json‘导入测试数据,并直接使用它们

至于browser.close()需求,如果它是一个工作流,一系列用户操作,我会将它们保存在一个文件中,以便在一个浏览器会话中运行它们。如果这些是不相关的测试,请分开规范,让wdio/mocha为您处理并行执行和浏览器会话。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39113199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档