nightwatchjs / nightwatch

https://github.com/nightwatchjs/nightwatch - 10.4k

    - v1.3.8 , 2020/08

 

https://nightwatchjs.org/api



    - 설치

npm i -g nightwatch

 

    - 크롬 드라이버 설치

npm install chromedriver --save-dev



    - nightwatch.conf.js 설정

 

desiredCapabilities: {

        browserName: 'chrome',

        chromeOptions: {

            

            args: [

                //'--no-sandbox',

                //'--ignore-certificate-errors',

                //'--allow-insecure-localhost',

                //'--headless'

                // 확장 추가로 로드

                '--load-extension=C:\\Users\\userID\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2\\Extensions\\cjpalhdlnbpafiamejdnhcphjbkeiagm\\1.29.2_0',

                '--auto-open-devtools-for-tabs', // 디버깅 툴 열기

            ]

        }

    },

    webdriver: {

        "start_process": true,

        "server_path": "node_modules/.bin/chromedriver",

        "port": 9515

    },

 

//-------------------------

    - 테스트 파일 작성 , test/test1.js

describe('Demo', function () {

    before(browser => browser.url('http://example.com'));

    test('Demo test', function (browser) {

        browser

            .waitForElementVisible('#word1')

            //더블 클릭

            .element('css selector', '#word1', function (ret) {

                this.moveTo(ret.value.ELEMENT, 0, 0, function () {

                    this.doubleClick()

                })

            })

            .perform(function (client, done) {

                console.log('perform', 123);

                client.getText('#word1', function (ret) {

                    console.log(ret);

                })

                done();

            })

            .pause(100000)

    });

    after(browser => browser.end());

 

    - 테스트 실행

nightwatch test/test1.js



//----------------------------

    - 사용자 정의 명령(Custom Command)

https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands

 

        - 설정 (nightwatch.conf.js 파일 수정) 

custom_commands_path: 'test/user',

 

    - test/user/user1.js 파일 생성

module.exports = class user1 extends Events {

    command(ms, cb) {

        console.log('user1', ms, cb);

    }

}



    - 작성한 명령 실행

    browser

            .waitForElementVisible('#word1')

            .user1(123)




'Code > JavaScript' 카테고리의 다른 글

[Javascript] 자연어 처리  (0) 2020.09.07
[Node.js] HTTP client  (0) 2020.08.24
[Node.js] 브라우저 테스팅 툴 NightWatch 사용법  (0) 2020.08.24
[Node.js] puppeteer - 브라우저 제어 사용방법  (0) 2020.08.24
[Javasctipr] Shadow DOM 사용법  (0) 2020.08.23
[JavaScript] Deno  (0) 2020.08.14
Posted by 코덴스

댓글을 달아 주세요