From 5ed0e4f7a273c987eab1551178241b3b69d1a4e0 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Mon, 12 Aug 2024 15:57:35 +0530 Subject: [PATCH] [js] Add service example (#1848) Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> --- .../javascript/test/drivers/service.spec.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 examples/javascript/test/drivers/service.spec.js diff --git a/examples/javascript/test/drivers/service.spec.js b/examples/javascript/test/drivers/service.spec.js new file mode 100644 index 000000000000..f0772239eb68 --- /dev/null +++ b/examples/javascript/test/drivers/service.spec.js @@ -0,0 +1,53 @@ +const Chrome = require('selenium-webdriver/chrome'); +const {Browser, Builder} = require("selenium-webdriver"); +const {getBinaryPaths} = require("selenium-webdriver/common/driverFinder"); +const options = new Chrome.Options(); + +describe('Service Test', function () { + it('Default service', async function () { + let service = new Chrome.ServiceBuilder() + + let driver = new Builder() + .forBrowser(Browser.CHROME) + .setChromeService(service) + .build(); + + await driver.get('https://www.selenium.dev/selenium/web/blank.html'); + await driver.quit(); + }); + + it('Set Driver Location', async function () { + + let options = new Chrome.Options(); + options.setBrowserVersion("stable") + + let paths = getBinaryPaths(options) + let driverPath = paths.driverPath; + let browserPath = paths.browserPath; + + options.setChromeBinaryPath(browserPath) + + let service = new Chrome.ServiceBuilder().setPath(driverPath) + + let driver = new Builder() + .forBrowser(Browser.CHROME) + .setChromeOptions(options) + .setChromeService(service) + .build(); + + await driver.get('https://www.selenium.dev/selenium/web/blank.html'); + await driver.quit(); + }); + + it('Set port', async function () { + let service = new Chrome.ServiceBuilder().setPort(1234) + + let driver = new Builder() + .forBrowser(Browser.CHROME) + .setChromeService(service) + .build(); + + await driver.get('https://www.selenium.dev/selenium/web/blank.html'); + await driver.quit(); + }); +}); \ No newline at end of file