Reference error By is not defined - selenium

I try to access a class using selenium and the keyword by , and the following error occurs :
ReferenceError: By is not defined
at Object.<anonymous> (C:\selenium\hello_world.js:11:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
The program is very simple
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
var client = webdriverio.remote(options);
client
.init()
.url('https://mail.google.com')
.findElement(By.className("TnvOCe k6Zj8d XraQ3b")).click()
.end();

You are using webdriverio, not Selenium. Code should be as follow.
client
.init()
.url('https://mail.google.com')
.click('.TnvOCe.k6Zj8d.XraQ3b')
.end();
You can find webdriverio API here.

Related

When in localhost AdminBro bundle function is taking path, but when deployed to the Vercel production getting error, why?

In the local server, it is working correctly. Only when deployed to Vercel getting this error.
This is the following code - (The error is occurring in the AdminBro.bundle as it is not taking the argument.)
imagePath: {
isVisible: { list: false, filter: false, show: true, edit: true },
components: {
show: AdminBro.bundle(
"components/admin-imgPath-component.jsx"
),
},
},
The error I am getting.
2021-08-26T18:14:08.075Z undefined ERROR ConfigurationError:
Given file "components/admin-imgPath-component.jsx", doesn't exist.
More information can be found at: https://softwarebrothers.github.io/admin-bro-dev/AdminBro.html
at Function.bundle (/var/task/node_modules/admin-bro/lib/admin-bro.js:375:13)
at Object.<anonymous> (/var/task/routes/admin.js:47:30)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/var/task/app.js:25:21)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
RequestId: ce1bf09a-857f-4c40-8a3b-e8a1762590bb Error: Runtime exited with error: exit status 1
Runtime.ExitError
You have to call
show: AdminBro.bundle(
"components/admin-imgPath-component"
),
WITHOUT extension at the end.
Make sure that adminjs automatically generates an folder with file .adminjs/.entry.js where the Component gets linked to the AdminJS instance.

Invalid shorthand property initializer error connecting to Mongo DB Atlas

I want to connect my project to Mongo DB Atlas. It shows the following error while connecting the Database:
me :~/Desktop/prod$ npm run server
> #0.1.0 server /home/me/Desktop/
> nodemon server.js
[nodemon] 2.0.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions:
js,mjs,json [nodemon] starting `node server.js` Url/keys.js:2
mongoURI = "mongodb+srv://<username>:<password>#cluster0-ttxhq.mongodb.net/test"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/saurabh/Desktop/prod/server.js:10:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10) [nodemon] app crashed - waiting for file changes before starting...
My code is :
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require("body-parser")
const app = express()
app.use(bodyParser.json())
const db = require("./config/keys").mongoURI
mongoose
.connect(db, {
useNewUrlParser: true,
useCreateIndex : true,
useUnifiedTopology : true
})
.then(()=>console.log("Database Connected"))
.catch(err => console.log(err))
const port = process.env.PORT || 5000
app.listen(port, ()=> console.log(`Server Starter on port ${port}`))
keys.js file is:*
modules.exports = {
mongoURI = "MONGODBURI"
}
Try:
modules.exports = {
mongoURI: "MONGODBURI"
}
This is a JSON so we cannot use '=' here.
have you tried IP whitelisting yourAtlas MongoDB cluster?
https://docs.atlas.mongodb.com/security-whitelist/
Medium tutorial

How can I retry failed end to end tests in Detox using Mocha?

I have a flaky end-to-end test that uses Detox and Mocha.
The Mocha test runner allows for multiple retries. I tried using the recommended Mocha syntax:
// auth.spec.js
describe('App authentication', () => {
this.retries(2);
it('should have a login screen', async () => {
await expect(element(by.id('LoginScreenView'))).toBeVisible();
});
});
However, it appears this is an empty object ({}) and does not have a retries function when running Detox with Mocha as the test runner.
It generates the following error:
node_modules/.bin/mocha __e2e__ --opts __e2e__/config/mocha.opts --
configuration ios.sim.debug --grep :android: --invert --artifacts-location "__e2e__/artifacts/ios.sim.debug.2018-10-17 22-51-12Z"
/<path>/__e2e__/auth.spec.js:10
this.retries(2);
^
TypeError: this.retries is not a function
at Suite.describe (/<path>/__e2e__/auth.spec.js:4:8)
at Object.create (/<path>/node_modules/mocha/lib/interfaces/common.js:112:19)
at context.describe.context.context (/<path>/node_modules/mocha/lib/interfaces/bdd.js:40:27)
at Object.<anonymous> (/<path>/__e2e__/auth.spec.js:3:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at /<path>/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/<path>/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/<path>/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/<path>/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
child_process.js:644
throw err;
^
Is there a way to automatically retry failed tests in Detox?
this in mocha can't work with arrow function, so must change it into ordinary one
// auth.spec.js
describe('App authentication', function () { // change it
this.retries(2);
It is not recommended best practice to use in Mocha
Ref:
https://mochajs.org/#arrow-functions
Hope it helps

Why am I getting gulp-changed error?

My gulpfile is below -
'use strict';
//dependencies
var gulp = require('gulp');
var sass = require('gulp-sass');
var minifyCss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var changed = requrie('gulp-changed');
Error after runnning gulp.
Error is for var changed = requrie('gulp-changed'); -
ReferenceError: requrie is not defined
at Object.<anonymous> (/home/lap1/Desktop/ReactJS/react-
test/gulpfile.js:9:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at execute (/usr/lib/node_modules/gulp-
cli/lib/versioned/^3.7.0/index.js:28:18)
at Liftoff.handleArguments (/usr/lib/node_modules/gulp-
cli/index.js:175:63)
Gulp version - 3.9.1
React native version - 2.0.1
I have installed all the dependencies both globally and for the project alone.
there iss a spelling mistake
Replace this
var changed = requrie('gulp-changed');
by
var changed = require('gulp-changed');

Protractor config file throws an error

I was running the same spec-test.js and config.js yesterday and it was working fine.
Today I tried and got the below error, This is happening on 2 out 3 machines:
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: SyntaxError: Unexpected identifier
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/FOLDERPATH/specs/spec-test.js:2:13)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
[launcher] Process exited with error code 100
I am using protractor 3.2.2, node 4.4.3
Any idea why the tests aren't executing.
PS: please ignore any file names mismatch/typos, since I have modified my code a little to ask on the forum. I have tried to run the below code but seeing the same error.
config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['specs/spec-test.js'],
capabilities: {
browserName: 'chrome',
chromeOptions: {
debuggerAddress: '127.0.0.1:9000'
}
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 700000,
isVerbose: true
}
};
spec-test.js
var fs = require('fs');
var panel = require('../pageObjects/file1.js');
var panelHelper = require('../pageObjects/file2.js');
var panelApp = require('../pageObjects/file3.js');
describe("Just print Hello world", function() {
it('test 1', function() {
console.log("Hello World!");
});
});
You must have a syntax error in one of those require pageObject files, like a missing comma or something. I can't see anything wrong in your config. Also the fact that it starts the webDriver instance means it is getting past onPrepare and starting the spec, so it's not your config file.
It would throw a different error if you had an issue in your config i.e. ERROR - failed loading configuration file config/local.conf.js. I would carefully look through those pageObject files for syntax errors.