0

http://nightwatchjs.org/gettingstarted의 단계를 수행했습니다. 그리고 내 테스트 파일에 내가 또한 http://nightwatchjs.org/guide/.waitForElementVisible은 Nightwatch 템플릿 프로젝트의 해결되지 않은 함수입니다.

module.exports = { 
    'Demo test Google' : function (browser) { 
    browser 
     .url('http://www.google.com') 
     .waitForElementVisible('body', 1000) 
     .setValue('input[type=text]', 'nightwatch') 
     .waitForElementVisible('button[name=btnG]', 1000) 
     .click('button[name=btnG]') 
     .pause(1000) 
     .assert.containsText('#main', 'Night Watch') 
     .end(); 
     } 
}; 

에서 다음 코드를 가지고,이 내 package.json의 모습 방법이다.

{ 
    "name": "try_nw", 
    "version": "1.0.0", 
    "description": "try_nightwatch", 
    "main": "nightwatch.js", 
    "scripts": { 
    "test": "node nightwatch -e chrome" 
}, 
    "author": "", 
    "license": "ISC", 
"dependencies": { 
    "bower": "^1.8.2", 
    "chromedriver": "^2.34.0", 
    "geckodriver": "^1.10.0", 
    "nightwatch": "^0.9.19", 
    "selenium-server-standalone-jar": "^3.8.1" 
    } 
} 

그리고 내 nightwatch.json

{ 
    "src_folders" : ["tests"], 
    "output_folder" : "reports", 
    "custom_commands_path" : "", 
    "custom_assertions_path" : "", 
    "page_objects_path" : "", 
    "globals_path" : "", 

    "selenium" : { 
    "start_process" : true, 
"start_session" : true, 
"server_path" : "bin/selenium-server-standalone-3.8.1.jar", 
"log_path" : "", 
"port" : 4444, 
"cli_args" : { 
    "webdriver.chrome.driver" : "bin/chromedriver.exe", 
    "webdriver.gecko.driver" : "", 
    "webdriver.edge.driver" : "" 
} 
}, 

"test_settings" : { 
"default" : { 
    "launch_url" : "http://localhost", 
    "selenium_port" : 4444, 
    "selenium_host" : "localhost", 
    "silent": true, 
    "screenshots" : { 
    "enabled" : false, 
    "path" : "" 
    }, 
    "desiredCapabilities": { 
    "browserName": "chrome", 
    "javascriptEnabled": true, 
    "acceptSslCerts": true, 
    "chromeOptions" : { 
     "args" : ["--no-sandbox", "--start-maximized", "--disable-infobars"] 
    } 
    } 
}, 

"chrome" : { 
    "desiredCapabilities": { 
    "browserName": "chrome", 
    "javascriptEnabled": true, 
    "acceptSslCerts": true 
    } 
}, 

"edge" : { 
    "desiredCapabilities": { 
    "browserName": "MicrosoftEdge" 
    } 
    } 
} 
} 

하지만, 내가 테스트를 실행할 때, 크롬의 빈 탭이 열리고 콘솔은 다음 출력을 보여줍니다.

Starting selenium server... started - PID: 15024 

[Googletests] Test Suite 
============================ 

Running: Demo test Google 

× Timed out while waiting for element <body> to be present for 1000 
    milliseconds. - expected "visible" but got: "not found" 

at Object.Demo test Google (E:\JS\Try_NW\tests\googletests.js:6:14) 
at process._tickCallback (internal/process/next_tick.js:150:11) 


FAILED: 1 assertions failed (5.972s) 

_________________________________________________ 

TEST FAILURE: 1 assertions failed, 0 passed. (6.088s) 

× googletests 

- Demo test Google (5.972s) 
Timed out while waiting for element <body> to be present for 1000 milliseconds. - expected "visible" but got: "not found" 
    at Object.Demo test Google (E:\JS\Try_NW\tests\googletests.js:6:14) 
    at process._tickCallback (internal/process/next_tick.js:150:11) 


Process finished with exit code 1 

그래서, < .waitForElementVisible>가 정의되어 있지 않습니다. 아무도 결정을 제안 할 수 있습니까?

+0

경우가 waitForElementVisible' 정의되지 않은'말합니까? o_O – Tomalak

+0

@Tomalak WebStorm은 이것을 설명하고 <미해결 함수 또는 메소드 vaitForElementVisible()>이라고 말합니다. –

+0

시간 초과를 늘려야한다고 생각합니다. 방금 테스트를 복사했고 첫 번째'waitForElementVisible()'이 정상적으로 작동했습니다. 내가 그것을 실행할 때 버튼을 찾고있는 사람이 폭발했다. – tehbeardedone

답변

0

발생하는 문제는 waitForElement가 아니거나 다른 스크립트가있는 것입니다. 그 이전의 setValue는 chromeDriver와 브라우저에서 다르게 작동합니다. 탭이 열리는 이유와 왜 오류 메시지가 body 요소를 찾지 못하는 이유입니다.

크롬 드라이버를 업데이트하면 스크립트를 작동시킬 수 있습니다.

https://sqa.stackexchange.com/questions/30150/chrome-62-sendkeys-seems-to-be-causing-chrome-settings-help-to-open

+0

제안 해 주셔서 감사합니다. FireFox에서 실행하면 작동합니다! Chrome에서 작동하지 않는 이유를 모릅니다. 다음 행을 변경했습니다. "webdriver.gecko.driver": "bin/geckodriver.exe", ","desiredCapabilities ": {"browserName ":"firefox ","javascriptEnabled ": true,"acceptSslCerts ": true} '] –

+0

아마도 chromeriver https://github.com/nightwatchjs/nightwatch/issues/1329의 버그입니다. –

0

테스트가 실패하는 원인이 있습니다. 나는 같은 1000 ms 타임 아웃으로 테스트를 수행 할 수 있었고 약간의 변경 만 가해도 괜찮 았습니다. 타임 아웃을 waitForElementVisible()으로 늘려보십시오. 다음 테스트는 나에게 문제없이 전달되었습니다.

browser 
    .url('http://www.google.com') 
    .waitForElementVisible('body', 1000) 
    .setValue('input[type=text]', ['nightwatch', browser.Keys.ENTER]) 
    .pause(1000) 
    .assert.containsText('#main', 'Night Watch') 
    .end();  
} 
+0

나는 이미 타임 아웃을 늘리려고했지만 성공하지는 못했다. 페이지가 여전히 비어 있습니다. –