私は過去数時間分器で遊んでいました。私が書いた最初のテストは、oauth2でログインをテストすることです。分裂器でOAuth2のログインフローを確実にテストする方法
この問題を手動でテストすると、ブラウザが初めて自分の資格情報を覚えていて、自動的にフローを終了します(つまり、ユーザー名/パスワードをもう一度入力する必要はありません)。このフローをもう一度やり直すには、ブラウザのデータを最初にクリアする必要があります。
私は分度器でこれを行う方法を考え出すことはできません。分度器を使って初めて、私はまだユーザー名とパスワードを送信する必要がありますしかし分度器は自動的に私のログインボタンをクリックします。そこで、以下のコードは渡し、私はsubmitBtn.click();
のコメントを解除した場合、テストは次のエラーで失敗します。
NoSuchElementError: No element found using locator: By(css selector, input.btn.btn-primary.btn-block)
at /usr/local/lib/node_modules/protractor/built/element.js:717:27
at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2896:21)
at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2775:27)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (internal/process/next_tick.js:103:7)Error
at ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/built/element.js:403:27)
at ElementArrayFinder._this.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/built/element.js:101:30)
at ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/built/element.js:740:22)
at public/test/e2e/login_with_github.spec.js:66:27
テストコード:
describe('login_with_github', function() {
it('login with github oauth2', function() {
browser.get('http://localhost:3001');
element(by.css('.btn-login-with-github')).click();
var loginField = element(by.id('login_field'));
var passwordField = element(by.id('password'));
var submitBtn = element(by.css('input.btn.btn-primary.btn-block'));
browser.getAllWindowHandles().then(function(handles) {
// switch to the newly openned window
let oldWindowHandle = handles[0];
let newWindowHandle = handles[1];
browser.switchTo().window(newWindowHandle).then(function() {
browser.ignoreSynchronization = true;
expect(loginField.waitReady()).to.eventually.be.ok;
expect(passwordField.waitReady()).to.eventually.be.ok;
expect(submitBtn.waitReady()).to.eventually.be.ok;
loginField.sendKeys('[email protected]');
passwordField.sendKeys(password);
//submitBtn.click(); // can't do this after the first time.
browser.switchTo().window(oldWindowHandle).then(function() {
browser.driver.sleep(2000);
expect(element(by.css('.foo')).getText()).to.eventually.contain('bar');
});
})
})
})
})
私は模倣することができますいずれかの解決策を探していますマニュアルテストプロセス、または分度器の懸垂問題を解決してください。この仕様を実行するたびに、ユーザー名/パスワードを入力し、サインインボタンをクリックし、リダイレクトを待ってメインページに戻ります。
アドバイスはありがとうございます!
EDIT
私はそれは違いはありません
beforeEach(function() {
console.log('port:', port);
browser.get('http://localhost:'+port);
browser.driver.manage().deleteAllCookies();
browser.executeScript('window.sessionStorage.clear();');
browser.executeScript('window.localStorage.clear();');
})
を試してみました。
あなたがしようとした持ち、各テストを実行するには、同じ問題を持っていたとき、私がやったいくつかのものですあなたが履歴で手で行ったことをシミュレートするには?browser.manage()。deleteAllCookies(); –
@JeremyKahan、はい、効果はありません。 browser.manageは分度器4.0.10のAPIドキュメントにはありません。 – swang
私はあなたがドキュメントについて正しいことを知っています。それは少し総額ですが、リフレッシュヘルプですか? –