2

I have scoured the documentation (what little there is) for selenium-webdriver located here (http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_Capabilities.html)

I can't find out what the equivalent code from Java to NodeJS would be.

Here is the code in JAVA (which I am copying from here at the Test Configuration Options section, https://github.com/zalando/zalenium/blob/master/docs/usage_examples.md#initial-setup)

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
  desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
  desiredCapabilities.setCapability(CapabilityType.PLATFORM, Platform.LINUX);
  desiredCapabilities.setCapability("name", "myTestName");

In particular I want to set the capability "name" so I can name my tests with Zalenium.

How do I do this in NodeJS?

This is my current selnium webdriver code which works (and was edited to remove sensitive info) but does not set the test name. I have tried this .withCapabilities(webdriver.Capabilities.chrome(),{"name","chrometest"}) and it compiles but I don't think it does anything?

//Run using this project (https://github.com/qmu/dockerfiles/blob/master/src/selenium-webdriver-node/example/bin/run)

"use strict";

const webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until,
    test = require('selenium-webdriver/testing');

//const expect = require('expect.js');
const assert = require('assert');

var driver = new webdriver.Builder()
   .withCapabilities(webdriver.Capabilities.chrome())
   .usingServer('http://localhost:4444/wd/hub')
   .build();

console.log('starting chrome...');

driver.manage().timeouts().implicitlyWait(10 * 1000);//10 seconds

driver.get('http://somewebsite.tech');
driver.findElement(webdriver.By.name('_username')).sendKeys('**');
driver.findElement(webdriver.By.name('_password')).sendKeys('**');
driver.findElement(webdriver.By.css("button")).click();
driver.quit();

//FIREFOX TESTS
console.log('starting firefox...');

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.firefox())
    .usingServer('http://localhost:4444/wd/hub')
    .build();

driver.manage().timeouts().implicitlyWait(30 * 1000);//10 seconds

driver.get('http://somewebsite.tech/');
driver.findElement(webdriver.By.name('_username')).sendKeys('**');
driver.findElement(webdriver.By.name('_password')).sendKeys('**');
driver.findElement(webdriver.By.css("button")).click();
driver.quit();


console.log('all modules are ready!');
Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154

2 Answers2

10

Ok I found out the answer. Turns out you just define it as extra parameters in an object.

var driver = new webdriver.Builder()
   .withCapabilities({'browserName': 'chrome','name':'Chrome Test','tz':'America/Los_Angeles','build':'Chrome Build','idleTimeout':'60'})
   .usingServer('http://localhost:4444/wd/hub')
   .build();

Hope this saves someone some frustration.

Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154
  • This is something I am trying to do just now. However, I am using webdriverio which has all the capabilities in the config file, so kinda struggling to get the capabilities working out in a test file. – Joseph Mar 18 '19 at 21:11
1

Thank you thank you for posting this. Was looking everywhere. Just as an FYI, some of your true strings need to be boolean. At least with geckodriver-v0.26.0, selenium 3.8.1, nodejs 10, and Centos6.

const driver = new webdriver.Builder()
      .forBrowser('firefox')
      .withCapabilities({"browserName": "firefox","acceptSslCerts": true,"acceptInsecureCerts": true})
      .setFirefoxOptions(options)
      .build();
Joe K
  • 11
  • 1