Skip to content

Instantly share code, notes, and snippets.

@MSakamaki
Last active August 29, 2015 14:17
Show Gist options
  • Save MSakamaki/370181fca3e21d95cf7e to your computer and use it in GitHub Desktop.
Save MSakamaki/370181fca3e21d95cf7e to your computer and use it in GitHub Desktop.
protractor memo

##browser.pause();でのデバッギング

画面を止めたいときに使う。

Ctrl+Cで止める。

conf.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

spec.js

describe('Protractor Demo App', function() {
  it('should add one and two', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');
    element(by.model('first')).sendKeys(3);
    element(by.model('second')).sendKeys(2);
    
    browser.pause();

    element(by.id('gobutton')).click();

    expect(element(by.binding('latest')).getText()).
        toEqual('5');
  });
});

実行コマンド

protractor debug conf.js

browser.debugger();でのデバッグ

node debuggerを使い、デバッグする。

細やかなデバッグで使用する。

### protractor config.js

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

spec.js

describe('Protractor Demo App', function() {
  it('should add one and two', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');
    element(by.model('first')).sendKeys(3);
    element(by.model('second')).sendKeys(2);
    
    browser.debugger();

    element(by.id('gobutton')).click();

    expect(element(by.binding('latest')).getText()).
        toEqual('5'); // This is wrong!
  });
});

実行コマンド

protractor debug conf.js

debug中のコマンド

Stepping#

  • cont, c - Continue execution
  • next, n - Step next
  • step, s - Step in
  • out, o - Step out
  • pause - Pause running code (like pause button in Developer Tools)

c,contを入力する事で、次のbreakpontまで移動する。

n,nextを入力する事で、次のbreakpontまで移動する。

replでscriptの実行を行う

この状態では、Ctrl+Cで抜ける事が出来る。

quitでデバッグを強制終了

##node-inspectorを使ったGUIデバッギング

実行コマンド`s

webdriver sever

webdriver-manager start

start node inspector

 node-inspector

Access Node inspector http://127.0.0.1:8080/debug?port=5858

go protractor debug

node --debug-brk `which protractor` conf.js 

conf.js

// conf.js
exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['spec.js']
}

spec.js

describe('Protractor Demo App', function() {
  it('should add one and two', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');
    element(by.model('first')).sendKeys(3);
    element(by.model('second')).sendKeys(2);
    
    debugger;

    element(by.id('gobutton')).click();

    expect(element(by.binding('latest')).getText()).
        toEqual('5');
  });
});
describe('Protractor Demo App', function() {
it('should add one and two', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.model('first')).sendKeys(3);
element(by.model('second')).sendKeys(2);
browser.debugger();
browser.pause(5859);
debugger;
element(by.id('gobutton')).click();
browser.debugger();
expect(element(by.binding('latest')).getText()).toEqual('5'); // This is wrong!
});
it('non angular site', function(){
browser.driver.get('http://www.yahoo.co.jp/');
browser.driver.sleep(3000);
browser.driver.findElement(by.name('p')).sendKeys('protractor');
browser.driver.findElement(by.id('srchbtn')).click();
browser.driver.sleep(5000);
// duty huck for protractor option browser.ignoreSynchronization = true
// see: http://ng-learn.org/2014/02/Protractor_Testing_With_Angular_And_Non_Angular_Sites/
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment