webdriverio 5.16 browser.element is not a function - node.js

i have a problem after i upgraded webdriver from 4.8 to 5.16:
My package.json
"#wdio/cli": "^5.16.15",
"#wdio/local-runner": "^5.16.15",
"#wdio/mocha-framework": "^5.16.15",
"#wdio/spec-reporter": "^5.16.11",
"#wdio/sync": "^5.16.15",
...
"chromedriver": "^79.0.0",
...
"selenium-webdriver": "3.0.0-beta-2",
....
"wdio-chromedriver-service": "^5.0.2",
"webdriverio": "^5.16.15",
then in my test i call:
browser.element('body')
result error:
browser.element is not a function
Was this function replaced (didn't find any notes about that)? and if so, whats the function to use now?
Or is there another problem? Help pls.

if I understand your question correctly, browser.element() is no longer available in v5.
As per their official changelog, it is changed to browser.findElement in v5.
You can also use browser.$() in place of browser.element().
Here is the complete list of changes in v5 if you have not figured it out yet.
https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md#v500-2018-12-20

browser.elements(...) no longer exists in v5.x - https://github.com/webdriverio/webdriverio/blob/master/CHANGELOG.md#boom-breaking-change-1
Just use
const elem = $('body')
to find first element, or
const divs = $$('div')
to find all elements, and get them in array.

If you are trying to get an array of the elements then you need
browser.elements('body') // plural
for single element just use
$('body')
Hope I got the idea right

Related

TypeError: Right-hand side of 'instanceof' is not an object (mongoose error)

I'm using these versions: "mongodb": "^3.6.3", "mongoose": "^5.10.18" and I'm having an issue where sometimes when I do a mongo SomeModel.create() in a cron job, it fails because of this error:
TypeError: Right-hand side of 'instanceof' is not an object and it fails on the node_modules/mongoose line in the screenshot below. This used to work completely fine and one day it just started happening without me changing the package versions or any other related code.
I see that I could revert back to a mongoose version like 3.9 that doesn't include the code in this screenshot but it still confuses me how this started to be flaky one day whereas it used to work perfectly fine on the same versions.
Here is roughly how I write my .create()
await Repayment.create({
userId: user._id,
isAutopay: true
});
Any ideas on how I can fix? Thanks!
screenshot is here

React native crypto stream module is undefined

I'm giving a try with [react-native-crypto][1] in order to learn how to convert nodejs to be used in React Native project in the future. Unfortunately, I couldn't get it running successfully. I've faced an issue with stream is undefined. ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[0], "stream").Transform.call').
If you have ever faced a similar problem, I'm so grateful for your help.
Also, I attach the screenshot of the issue as the following
For anyone still trying to solve this issue, I have figured out a solution that worked for me. So within node_modules/cipher-base/index.js, the top of the file should have a line which defines the variable Transform as var Transform = require('stream').Transform. For some reason, it does not like the module stream and as such it needs to be changed to readable-stream. Therefore the variable Transform should now read var Transform = require('readable-stream').Transform.
From what I have gathered, the stream module it is trying to refer to isnt actually a module that can be used. The reason why it gets referenced however seems to be because the tsconfig.json file in the root directory specifies "stream": ["./node_modules/readable-stream"] as a path, almost as if to make stream refer to the readable-stream module, which in theory it should refer to when it is called. But in this case it doesnt happen so we need to explicitly define that we are refering to the readable-stream module.
Hope this helps anyone else out there and prevents others scratching their heads for hours on end like it did for me!
I have figured it out by editing in metro.config.js as the following:
resolver: {
extraNodeModules: {
stream: require.resolve('stream-browserify'),
}
},

Get maxSatisfying version including pre-release with node semver

How can i get the latest version (including the pre-releases) from an array of versions using node/semver.
For example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*"));
Returns null, but i want to get the 1.0.0-rc.11 back.
Kind Regards and have a nice day!
You need to add the includePrerelease option to your maxSatisfying method as described here: https://github.com/npm/node-semver#functions
In your example:
var semver = require("semver");
var versions = ["1.0.0-rc.10","1.0.0-rc.11"];
console.log(semver.maxSatisfying(versions, "*", {
includePrerelease: true
}));
Okay i've found a solution.
The node module semver-extra adds some nice extra functions to the semver library, also one for getting the max version including the pre-releases.
https://www.npmjs.com/package/semver-extra

How to be absolutely sure that socket.io is working?

Normally, in order to know that it's started, there's a message in Node that says "info - socket.io started". However, for some reason, I'm not getting it. Could be a version thing.
So is there another way to know if my socket is up and listening?
Have you recently updated Socket.io from version 0.9 to 1.x? The default values for log reporting changed with version 1.0, and it's less verbose by default.
See the upgrade documentation.
PS: If you upgraded Socket.io and you didn't even realize it, then it's because your "package.json" file does not lock versions. I'd strongly advise AGAINST using * as version: always be more specific, locking the versions at least to the minor version (as per semver). For example:
// In package.json, under "dependencies":
// NOT SAFE: this always gets the last version, which may have some breaking change (as per semver, with version X.Y.Z, changes in X allow breaking changes in APIs)
"socket.io": "*"
// POSSIBLY SAFE: this does not update to the new major version, so API compatibility *should* be always maintained (however, it's not 100% safe too, to be used carefully)
"socket.io": "1.x"
// SAFE: this allows updates that contain bug fixes and minor additions; API-compatibility should always be guaranteed
"socket.io": "1.0.x"
"socket.io": "1.0.*" // equivalent
"socket.io": "~1.0.4" // equivalent

Mongoid pagination

I tried
#posts = Post.page(params[:page]).per_page(10)
and
#posts = Post.paginate(:page => 1, :per_page => 10)
but neither method works
undefined method `page' for Post:Class
undefined method `paginate' for Post:Class
How do you do pagination with mongoid?
You should use Kaminari https://github.com/amatsuda/kaminari
This works fine for me:
#posts = Post.paginate(:page => 1, :limit => 10).desc(:_id)
desc(:_id) is added so that latest posts could be listed first.
Still using will_paginate is also okay.
This thread has same issue: undefined method `paginate' for Array on Rails 3 with mongoid
The main point to fix the error is to add this line before the controller call paginate library:
require 'will_paginate/array'
It should be added to default config file if you use mongoid for the whole project.
Hope the explanation helpful.
Reference from origin gem source: https://github.com/mislav/will_paginate/wiki/Backwards-incompatibility at "WillPaginate::Collection" section.
P/S: this is just a work around if your query is not very large. If you want better performance, let's try mongoid-pagination gem, custom will_pagination gem or another pagination gem which supported Mongoid like kaminari.
A bit late, but for anyone else looking, I found 'will_paginate_mongoid'
https://github.com/lucasas/will_paginate_mongoid
Really straight forward and lets you simply do
collection.skip(20).limit(10)
Use the following gem.
Very helpful.
https://github.com/lucasas/will_paginate_mongoid
To update a bit the answers, now exists the Pagy gem, also much more performant (cpu/mem) than will_paginate and kaminari. This is a migration guide
silly thing, but it worked for me in sinatra after i added require 'mongoid-pagination'
to app.rb
Posting several years later, in case someone else faces the same challenge.
kaminari-mongoid was released in 2016, and is currently maintained.
https://github.com/kaminari/kaminari-mongoid
All the goodness of Kaminiari for Mongoid, including appropriate handling of Mongoid::Criteria results, which was possibly the cause of the OP's error.

Resources