2017-06-14 12 views
1

分度器を初めて使用しています。ここに私の設定ファイルが分度器テストの実行中に問題が発生する

configです:

exports.config = { 
seleniumAddress: 'http://localhost:4444/wd/hub', 

capabilities: { 
    'browserName': 'chrome' 
}, 

specs: ['./protractor-tests/*.js'], 

jasmineNodeOpts: { 
    showColors: true 
} 
} 

ここで私は私が見通しとするとき、それはホーム・ページにリダイレクトログイン時にクリックして、ログインユーザーログインをテストしていたシナリオを持っています。

ログインテスト:

exports.login = function() { 
describe('Login Test', function() { 
    beforeEach(function() { 
     browser.get('http://domain/login'); 
    }); 
    afterEach(function() { 
     browser.ignoreSynchronization = false; 
    }); 
    it('It should redirect to outlook for auth', function() { 
     browser.ignoreSynchronization = true; 
     var currentUrl; 
     browser.getCurrentUrl().then(function(url) { 
      currentUrl = url; 
     }).then(function() { 
      browser.wait(function() { 
       return browser.getCurrentUrl().then(function(url) { 
        return url !== currentUrl; 
       }); 
      }); 
     }).then(function() { 
      setTimeout(function() { 
       var userName = element(By.xpath('/html/body/div[1]/header/div[1]/section/div[2]/apt-user-profile/div/div/button[1]/span/span')); 
       if (userName) 
        expect(browser.getCurrentUrl()).toContain('http://domain/home'); 
       else 
        expect(browser.getCurrentUrl()).toContain('https://login.microsoftonline.com'); 
      }, 10000); 


     }); 
    }); 

    it('It should login into the application and display user as Tom White', function() { 
     setTimeout(function() { 
      browser.driver.findElement(by.id('cred_userid_inputtext')).sendKeys('[email protected]'); 
      browser.driver.findElement(by.id('cred_password_inputtext')).sendKeys('****'); 
      browser.driver.findElement(by.id('cred_sign_in_button')).click(); 
      var userName = element(By.xpath('/html/body/div[1]/header/div[1]/section/div[2]/apt-user-profile/div/div/button[1]/span/span')); 
      expect(userName.getText()).toEqual('Hello Tom White'); 
     }, 10000); 
    }); 

}); 
} 

は、これらのテストケースは実際には正常に動作しているが、ホーム・ページでは、私もそれがエラー

で失敗しているいくつかの他のページに私をリダイレクトする要素をクリックする必要がある場合
Failed: javascript error: document unloaded while waiting for result 

ホームテスト:

var loginPage = require('./loginTest.js'); 

describe('Home Test', function() { 
    loginPage.login(); 
    it('It should click product', function() { 

      var productMenu = element(By.xpath('/html/body/div[1]/headerdiv[1]/section/div[1]/apt-nav-bar/div/div[2]/div[2]/ul/li[2]/a/span')); 
      productMenu.click(); 
      expect(browser.getCurrentUrl()).not.toEqual('http://domain/home'); 
      expect(browser.getCurrentUrl()).toEqual('http://domain/products'); 


     }) 

}); 

すべてのヘルプは高く評価されるだろう。

答えて

0

あなたの問題は、ページが何かをするのを待っていないことが原因です。分度器によって提供されるExpectionConditions機能を使用して明示的に待機を実装できます。ここにはAPIのリンクがあります。

汚れた解決策は、実行が特定の期間、たとえば5秒間中断されるように、sleep()メソッドを使用することです。だからbrowser.sleep(5000)を試すことができます。これはエラーを回避するはずです。しかし、これは良い解決策ではありません。

編集1:分度器構成ファイルに定義されているexports.configオブジェクトのrootElementパラメータは、ng-appディレクティブを含む要素と一致する必要があります。

<div ng-app="myApp" class="my-app"> 

出典:SO PostあなたのHTMLがあるときに、あなたの分度器-conf.jsで

rootElement: '.my-app', 

を追加してください。

+0

:「window.angularが –

+0

定義されていないbeforeEach()beforeAll()へのごloginPage.login();コールを移動更新された答え。上記を参照してください。 – demouser123

0

login関数は、it以外の関数、すなわち、分度器の制御フローの下にある関数 "before"または "after"の外に呼び出すことになります。分度器がページと同期するのを待っている間エラー:私はbrowser.sleep(5000) をすれば、私は、エラー失敗を取得mは

describe('Home Test', function() { 
    beforeEach(function() { 
     loginPage.login(); 
    }); 

    it('It should click product', function() { 
     var productMenu = element(By.xpath('/html/body/div[1]/headerdiv[1]/section/div[1]/apt-nav-bar/div/div[2]/div[2]/ul/li[2]/a/span')); 
     productMenu.click(); 
     expect(browser.getCurrentUrl()).not.toEqual('http://domain/home'); 
     expect(browser.getCurrentUrl()).toEqual('http://domain/products'); 
    }) 
}); 
関連する問題