2016-08-24 9 views
0

私はMochaとChaiで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()を試しましたが、2番目のテストを呼び出すと正常に動作しませんでした。 mochaとchaiの方がブラウザを閉じ、セッションをリセットしてブラウザを開いてホームページに行くより良い方法はありますか?

1)試験はチャイを使用してアサーションとモカに書かれている必要があります

これらは私が与えられた要件でした。テストを実行するために使用される フレームワークはwebdriverIOでなければなりません。ネイティブのセレンコマンドはありません。

2)試験は、おそらくそのようなユーザ メール/パスワードのような他の試験()で使用される変数は別に保存されるべきである)ページオブジェクトパターン

3を利用するように書かなければなりませんテストファイル

答えて

1

コード外の変数を格納するには、いくつかの方法があります。

  1. あなたはwdio.conf.jsを活用し、this ようcustomConfigオブジェクトの追加を開始し、コード_page.navigate(browser.options.customConfig.baseUrl);
  2. this様または別の.jsonファイルに保管し、それらを使用し、あなたの中に持って nconfを使用することができますテストコード
  3. それとも単に「./testdata.json」からインポートテストデータのようdata.jsonインポートし、(限りbrowser.closeとして直接

それらを使用する)、要件、そのワークフロー、SER場合ユーザーのアクションのために、1つのファイルで1つのブラウザセッションで実行するようにしています。 これらが関係のないテストの場合は、仕様を分けて、wdio/mochaにパラレル実行とブラウザセッションを処理させてください。

関連する問題