I am using WebStorm to write some automated tests. For one test, I must check if an alert prompts the user. To accomplish this, I want to use the .getAlertText(); method, however WebStorm does not recognize the method. It says "Unresolved function or method getAlertText()".
The WebdriverIO documentation shows that it is indeed a method: https://webdriver.io/docs/api/webdriver.html
How can I get WebStorm to allow me to use the method? Thank you.
Unfortunately, this method is missing in wdio typings, that's why the IDE can't resolve it during static code analysis.
I believe that this has to be submitted to either https://github.com/DefinitelyTyped/DefinitelyTyped/issues or https://github.com/webdriverio/webdriverio/issues
Reference:
http://v4.webdriver.io/api/protocol/alertText.html
v4 have function alertText(); && v5 have getAlertText()
Related
I'm studying Javascript using Visual Code and every time a similar exercise that uses 'event' (the event shows in the code with the strikethrough like e̶v̶e̶n̶t̶) appears I can't complete it because of this annoying issue. In the description pop up a warning showing the issue ("event is deprecated ts(6385)"). I look out in the forums and stack over flow but I can not find any answer for this problem, only a few places says the lib dom and #deprecated, but I don't what to do.
Please, any way to help and learn to pass this problem out will be very useful.
function sayMyFirstName(element){
alert("My First name is..." + element.value)
}
function sayMyLastName(){
console.log(event)
}
It sounds like you're getting TypeScript validation for a simple JS project. There are several things you can try:
In your settings file (settings.json):
"typescript.validate.enable": false
... OR ...
In your .js source file(s):
/*tslint:disabled*/
A separate issue is why you're getting the "deprecation" warning in the first place. This is the reason:
https://developer.mozilla.org/en-US/docs/Web/API/Window/event
The read-only Window property event returns the Event which is
currently being handled by the site's code. Outside the context of an
event handler, the value is always undefined.
You should avoid using this property in new code, and should instead
use the Event passed into the event handler function. This property is
not universally supported and even when supported introduces potential
fragility to your code.
In other words, "event" should really be passed as an argument to a JS event handler. You shouldn't be using the global object; you shouldn't NEED to use the global object.
Here are a few good tutorials:
Introduction to events (MDN.com)
JavaScript Events
Strong suggestion:
If you're learning JavaScript, please make sure your study materials are up-to-date (definitely covering ES6!). This is a good book: Secrets of the JavaScript Ninja 2nd Edition
It looks to me that the TypeScript Validator is saying the implicit passing of event is deprecated. A simple fix would be to pass the event into the function as a parameter
function sayMyLastName(event){
console.log(event)
}
I'm migrating a lot of functionality from JS to Angular and found this issue a lot
You can use "window.event" to replace the deprecated "event".
You just need to open >Preferences: Open Workspace Settings (JSON) by Ctrl + Shift + P in VSCode then add this line to JSON file "editor.showDeprecated": false to disable a show deprecated in case if you only need to some workspace.
If you want to disable all workspace then use >Preferences: Open Settings (JSON) instead.
do any of you face this problem , where vscode always take you to the type definition of a function and not the implementation.
For example,
I right click on the react setState function as below,
And VS code shows me the typescript file.
If its problem a, how do i fix it.
If not then how do I look at the implementation and not the type definition of a function.
This is a limitation of VS Code's intellisense. We don't attempt to parse js from inside node_modules for IntelliSense, so we have no way of mapping back to the original source code. Instead we rely on *.d.ts to provide definitions.
These two issues are tracking possible improvements to this:
https://github.com/Microsoft/TypeScript/issues/6209
https://github.com/Microsoft/TypeScript/issues/16792
In vscode v1.67 there is update with new Go to Source Definition command
Jump directly to a JavaScript implementation of a library function
using the new Go to Source Definition command. You can learn more
about this feature and share feedback in TypeScript issue #49003.
Sorry I don't know if this is a stupid question or not but I cannot find the answer.
I have a pure function in javascript which check if the argument is a correct URL
isValidUrl(url) {
const protocol = new URL(url).protocol;
...
}
The code runs fine in browser. But I would like to write a test using mocha for it. And mocha complains "ReferenceError: URL is not defined". So does that mean server side JS does not have URL class? Do I need to use something like headless browser to test it?
Thanks a lot.
Node and friends, where your tests are likely running, implement the ECMAScript (JS) spec. The URL class is from this WhatWG spec. The JS spec does not have any reference to a URL class, which explains your immediate problem.
Node also implements its own CommonJS-based modules, one of which is a URL module. It doesn't appear to have the same interface, however.
Using Mocha with Karma to run tests in a headless browser, like PhantomJS, is probably a better solution. You'll get an accurate, if slightly out of date, version of chromium to test within. You can also set Karma up to use other browsers, if they are available on the test machine.
I`m using phpstorm with protactor for angular and for some reason the IDE doesnt recognize some
functions. but the functions is working fine when i`m running the test.
for example:
element(by.buttonText('toggle')).click();
expect(element(by.css('.net-fade')).getText()).
toEqual('something');
})
The IDE tell me that the method by.css is "unresolved function or method".
Someone know how to fix it?
I'm not familiar with PHPStorm, so this won't be a full-answer:
But I'd say the basic problem is that Protractor binary auto-inserts protractor.js and other dependencies into the environment for you. This is what gives you by (along with other helper variables browser, element, etc).
You may want to insert protractor.js yourself, you can find it in
node_modules/protractor/lib/protractor.js
(And again, I am unsure of how PHPStorm includes files, but you might want to only manually add protractor.js if it is not running in test mode. And to this end, you could set flag in protractors onPrepare() function to check against).
I'm writing an e2e test suite using Protractor.
I know it's built on top of WebdriverJS, and I'm trying to using some webdriverJS functionality.
Namely, I'm trying to enqueue some behavior using the webdriverJS' promise manager, and the WebdriverJS documentation says I should use
webdriver.promise.controlFlow().execute(function myBehavior(){...});
Trouble is, I don't know how to access that "webdriver" object. There is no global variable named "webdriver".
Can someone help me on this?
EDIT:
Now that the question has been solved, I'd like to highlight the fact that one must use
browser.driver.controlFlow()
and not
browser.driver.promise.controlFlow()
despite what WebdriverJS documentation may suggest.
The documentation says browser.driver is the underlying webdriver.
So can you try this:
browser.driver.controlFlow().execute(function myBehavior(){...});