Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Target browser must be a string" Builder still expects browser. #42

Closed
Rup1 opened this issue Nov 6, 2020 · 3 comments
Closed

"Target browser must be a string" Builder still expects browser. #42

Rup1 opened this issue Nov 6, 2020 · 3 comments

Comments

@Rup1
Copy link

Rup1 commented Nov 6, 2020

Hello, I am running on MacOS with the following package versions

"selenium-appium": "0.0.16",
"selenium-webdriver": "^4.0.0-alpha.7"

I have the following code:

const Webdriver = require('selenium-appium').WebDriver2;
const By = require('selenium-appium').By2;

const caps = {
    platformName: 'Mac',
    deviceName: "Mac",
    app: "Mail"
};

async function main() {
  const webdriver = new Webdriver();
  await webdriver.startWithCapabilities(caps)
  const element = await By.xpath("/AXApplication[@AXTitle='Mail']/AXWindow[@AXTitle='Inbox (1 message)' and @AXIdentifier='_NS:15' and @AXSubrole='AXStandardWindow']/AXGroup[@AXIdentifier='_NS:10']/AXCheckBox[@AXTitle='Sent' and @AXSubrole='AXToggle']");

  await element.click();
  await webdriver.quit()
}

main();

This causes

(node:18125) UnhandledPromiseRejectionWarning: TypeError: Target browser must be a string, but is <undefined>; did you forget to call forBrowser()?
    at Builder.build (/Users/User/Desktop/dev/appium-instagram/node_modules/selenium-webdriver/index.js:589:13)
    at Promise (/Users/User/Desktop/dev/appium-instagram/node_modules/selenium-appium/dist/driver.js:187:22)
    at new Promise (<anonymous>)
    at WebDriver2.startWithCapabilities (/Users/User/Desktop/dev/appium-instagram/node_modules/selenium-appium/dist/driver.js:182:16)
    at main (/Users/User/Desktop/dev/appium-instagram/macOsCalculator.js:13:19)
    at Object.<anonymous> (/Users/User/Desktop/dev/appium-instagram/macOsCalculator.js:20:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
(node:18125) 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:18125) [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.

Initially I tried using the official selenium-webdriver as found in one of your examples but this didn't work either.

const Builder = require('selenium-webdriver').Builder;
const By = require('selenium-appium').By2;

const url = 'http://localhost:4723/wd/hub'

const caps = {
    platformName: 'Mac',
    deviceName: "Mac",
    app: "Mail"
};

async function main() {
  const webdriver = await new Builder()
    .usingServer(url)
    .withCapabilities(caps)
    .build()

  const element = await webdriver.wait(until.elementLocated(By.xpath("/AXApplication[@AXTitle='Mail']/AXWindow[@AXTitle='Inbox (1 message)' and @AXIdentifier='_NS:15' and @AXSubrole='AXStandardWindow']/AXGroup[@AXIdentifier='_NS:10']/AXCheckBox[@AXTitle='Sent' and @AXSubrole='AXToggle']")));
    await element.click();
    await webdriver.quit()
}

main();

I understand you are from Microsoft and that your examples show this working on windows. Does this mean this wouldn't work at all with Appium For Mac? The error seems agnostic of the platform.

@licanhua
Copy link
Collaborator

licanhua commented Nov 7, 2020

I guess the error is raised from internal/modules/cjs/loader.js:537. From the output, likely, you should set browserName(possible browser) to something in cap but I don't know what exactly value it want

const caps = {
browserName:'something'
platformName: 'Mac',
deviceName: "Mac",
app: "Mail"
};

@Rup1
Copy link
Author

Rup1 commented Nov 12, 2020

I tried passing a variety of browser strings but same result.

@licanhua
Copy link
Collaborator

You can ask Appium For Mac that what kind of capabilities is required. I don't know too much about Mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants