2016-05-11 19 views
1

私の目標は、knockoutJSページ(ページ上にAngularJSは全くありません)でe2eテストを実行することです。私はこのテストに分度器を使い始めました。 browser.ignoreSynchronization=trueと約束を多用した場合、仕様は正しい順序で実行されているように見えますが、expectのステートメントが見つかったようです。私はメッセージNo specs foundを受け取ったにもかかわらず、expectの文を内部に持つitコールが3つあります。KnockoutJSを使った分度器

PS C:\> protractor conf.js 
[09:38:08] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
[09:38:08] I/launcher - Running 1 instances of WebDriver 
load the page in the browser. use promises to keep the flow of the tests accurate 
Started 


No specs found 
Finished in 0 seconds 
wait for the form to load (check presence of specific input 
change select to specific option in order to show additional content on the page 
wait for addtional fields to load completely 
test that the additional field is present. 
update the source field with the test value 
Test that the targetField has the highlight class. 
update the target field with the test value. 
Test that the targetField does not have the hightlight class. 
[09:38:13] I/launcher - 0 instance(s) of WebDriver still running 
[09:38:13] I/launcher - chrome #01 passed 

私の研究は、使用して分度器がAngularJSのために提唱されていることを示している:私は次の出力を得る

var debug = true; 

describe('check for highlighting', function() { 

    var url = 'http://domain/page.aspx', 
    formLoadedField = 'NameField', 
    selectId = 'Action', 
    selectValue = 'Change Values Option', 
    testValue = 'Some Test Value!!', 
    sourceField = 'FromField', 
    targetField = 'ToField', 
    EC = protractor.ExpectedConditions; 

    browser.ignoreSynchronization = true; 

    log('load the page in the browser. use promises to keep the flow of the tests accurate'); 
    browser.get(url)  
    .then(function(){ 
     log('wait for the form to load (check presence of specific input)'); 
     browser.wait(EC.presenceOf(element(by.id(formLoadedField))), 5 * 1000); 

     log('change select to specific option in order to show additional content on the page'); 
     element(by.cssContainingText('#'+selectId+' option', selectValue)).click();  
    }) 

    .then(function(){ 
     log('wait for addtional fields to load completely'); 
     browser.wait(EC.presenceOf(element(by.id(targetField))), 5 * 1000); 
    }) 

    .then(function(){ 
     log('test that the additional field is present.'); 
     it('should have a targetField element', function() { 
     expect(EC.presenceOf(element(by.id(targetField)))).toBe(true); 
     }); 
    }) 

    .then(function(){   
     log('update the source field with the test value'); 
     element(by.id(sourceField)).sendKeys(testValue); 

     log('Test that the targetField has the highlight class.'); 
     it('targetField should be highlighted when values are different', function() { 
     expect(hasClass(element(by.id(targetField)),'highlight')).toBe(true); 
     }); 
    }) 

    .then(function(){ 
     log('update the target field with the test value.'); 
     element(by.id(targetField)).sendKeys(testValue); 

     log('Test that the targetField does not have the hightlight class.'); 
     it('targetField should NOT be highlighted when values are equal', function() { 
     expect(hasClass(element(by.id(targetField)),'highlight')).not.toBe(true); 
     }); 
    }); 

}); 

function log(msg){ 
    if(debug){ 
     console.log(msg); 
    } 
} 

は、ここに私のコードです。私は は(KnockoutJSページ上のE2Eテストを)しようとしています何のためにジャスミンの代わりに、分度器を使って

  • いくつかの提唱者。
  • 分度器は でKnockoutJSページのテストには十分だと言われていますが、テストのタイミングは 自分で管理する必要があります(分度器の重要な機能)。
  • 私は、テストの前にignoreSynchronizationをtrueに設定してから 、その後にfalseに戻っていましたが、それは私が を探している(または私は戦略を誤解しています)結果を与えませんでした。
  • 私は以前にテストを実行することができましたが、非同期 の分度器の性質のため、テストは ページの変更と同期していなかったため、テストは無関係でした。

私はあなたのご意見をお待ちしております。

答えて

1

それはちょうどあなたがあなたのテストを発見するためにProtractor/WebDriverJS Control Flowとジャスミンの上に置くことを約束ためにbeforeEach()it()ブロックを使用する必要があるということです。

var debug = true; 

describe('check for highlighting', function() { 

    var url = 'http://domain/page.aspx', 
    formLoadedField = 'NameField', 
    selectId = 'Action', 
    selectValue = 'Change Values Option', 
    testValue = 'Some Test Value!!', 
    sourceField = 'FromField', 
    targetField = 'ToField', 
    EC = protractor.ExpectedConditions; 

    beforeEach(function() { 
    browser.ignoreSynchronization = true; // TODO: move to onPrepare 

    log('load the page in the browser. use promises to keep the flow of the tests accurate'); 
    browser.get(url).then(function(){ 
     log('wait for the form to load (check presence of specific input)'); 
     browser.wait(EC.presenceOf(element(by.id(formLoadedField))), 5 * 1000); 
     log('change select to specific option in order to show additional content on the page'); 
     element(by.cssContainingText('#'+selectId+' option', selectValue)).click();  
    }).then(function(){ 
     log('wait for addtional fields to load completely'); 
     browser.wait(EC.presenceOf(element(by.id(targetField))), 5 * 1000); 
    }); 
    }); 

    it('should have a targetField element', function() { 
    expect(EC.presenceOf(element(by.id(targetField)))).toBe(true); 
    }); 

    // ... 
}); 

いくつか提唱者をジャスミンを使用して代わりに私が試しているもののための分度器(KnockoutJSページのe2eテスト)。

ジャスミンと分度器は代替ではありません。 Jasmineは、分度器が使用できる(デフォルトで使用する)testing frameworkです。 CucumberJSのように、Jasmineの代わりに他のテストフレームワークを使用することもできます。

分裂器はKnockoutJSページをテストするのには十分だと言う人もいますが、テストのタイミングを自分で管理する必要があります(分度器の重要な機能です)。

分度器を使用して、任意のWebアプリケーションをテストすることができます。 AngularJSアプリケーションのテストに使用されるときは、組み込みシンクと特定のロケータが搭載されているので、分度器は本当に輝きます。しかし、あなたは持っているKnockoutJSアプリをテストするためにそれを使うべきです(ちょっと言ってください)。ちょうどbrowser.ignoreSynchronization = true;で同期をオフにする必要があります。分度器はまだWebDriverJSの非常に優れたラッパーであり、便利で機能豊富なAPIを備えています。

+0

@ alec.xe入力と方向をありがとうございます。質問:コードを変更すると、各テストに新しいブラウザセッションが必要になります。ページの値が変わるたびに一連のテストが完了するように設定できますか? – Bill

+1

@Billよく、きれいなブラウザセッションで各テストを開始し、 'beforeEach'または' beforeAll'の中をナビゲートするのが一般的なパターンです。http://stackoverflow.com/questions/25740056/keep- protractor-browser-session-alive ..thanksです。 – alecxe

+0

@ alec.xeありがとう! – Bill