2016-08-24 45 views
0

我是使用摩卡和柴的webdriver-io的新手。这里首先是我的脚本:一些Webdriver IO Mocha Chai问题

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(),但是在调用第二个测试时它似乎不能正常工作。摩卡和柴有没有更好的方式来关闭浏览器,重置会话并打开浏览器并进入主页?

这些是我被给出的要求:

1)试验必须写在摩卡使用柴断言。用于驱动测试的 框架必须是webdriverIO - 没有本地selenium命令。

2)试验应写入在利用页面对象图案,将有可能在其它测试(诸如用户 电子邮件/密码被用于

3)的变量的方法)应分别从被存储测试文件。

回答

1

为了存储代码之外的变量,有几种方法。

  1. 你可以利用wdio.conf.js并开始增加customConfig对象像this 并在代码_page.navigate(browser.options.customConfig.baseUrl);使用它们像this
  2. 或保持在一个单独的上传.json文件,使用nconf带入您的测试代码
  3. 或者干脆从“./testdata.json”导入data.json像进口TESTDATA直接

尽量使用它们作为browser.close()的要求,如果它的工作流程,SER用户操作,我会将它们保存在一个文件中,以便在一个浏览器会话中运行它们。 如果这些是不相关的测试,单独的规格,并让wdio/mocha为您处理并行执行和浏览器会话。

相关问题