I'm trying to automate testing with Selenium × Node.js, but it got blocked at the investigation stage...
1. Installation of Node.js
From official site
2. Installation of selenium-webdriver
Install via npm
$ npm install selenium-webdriver
3. Installation of selenium-server
Install via Homebrew
$ brew install selenium-server-standalone
4. Install of ChromeDriver
ChromeDriver - WebDriver for Chrome
→ Move the file after downloading the driver
$ mv /Users/username/Downloads/chromedriver ./
$ ls -la
total 31920
drwxr-xr-x 7 username staff 238 5 24 17:42 .
drwxr-xr-x+ 55 username staff 1870 5 24 17:42 ..
-rwxr-xr-x@ 1 username staff 11917200 4 20 16:39 chromedriver
drwxr-xr-x 41 username staff 1394 5 24 16:45 node_modules
-rw-r--r-- 1 username staff 9367 5 24 16:45 package-lock.json
5. Start-up the Selenium Server
$ selenium-server -port 4444 & [1] 33415 C02SY1XFGTFJ:selenium username$ 18:04:14.512 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.11.0', revision: 'e59cfb3' 18:04:14.513 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444 2018-05-24 18:04:14.624:INFO::main: Logging initialized @441ms to org.seleniumhq.jetty9.util.log.StdErrLog 18:04:14.882 INFO [SeleniumServer.boot] - Welcome to Selenium for Workgroups.... 18:04:14.882 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
Write a test code as a sample
$ vim sample.js
// Initialization of WebDriver
const webdriver = require('selenium-webdriver');
// Browser selection
const browser = new webdriver.Builder().forBrowser('chrome').build();
// Get page title
browser.get('http://example.selenium.jp/reserveApp/').then(()=>{
browser.getTitle().then(title => console.log('Page title:',title))
});
// Exit the browser
browser.close();
browser.quit();
When you execute the above code, ...
$ node sample.js
(node:13216) UnhandledPromiseRejectionWarning: NoSuchSessionError: no such session
(Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.12.6 x86_64)
at Object.checkLegacyResponse (/Users/ko-kamenashi/selenium/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (/Users/ko-kamenashi/selenium/node_modules/selenium-webdriver/lib/http.js:533:13)
at Executor.execute (/Users/ko-kamenashi/selenium/node_modules/selenium-webdriver/lib/http.js:468:26)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:13216) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:13216) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I got the errors. What shoud I do? Could you lend me a hand? Thank you for your reading.
The error is here: const browser = new webdriver.Builder().forBrowser('chrome').build();
Best way:
(async ()=> {
await const browser = new webdriver.Builder().forBrowser('chrome').build();
)();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With