vue-cli3+electron+chromedriver+selenium-webdriver cannot find element - selenium-webdriver

I use vue-cli project (that installed electron+seleniumWebDriver) run tests with ChromeDriver.
I keep running chromedriver (that installed in my vue-cli project) then I ran the test file 'node ff.js'.
The Electron app was run in screen but nothing happened. Then wait till the process exited, the result became error 'UnhandledPromiseRejectionWarning: WebDriverError: unknown error: DevToolsActivePort file doesn't exist'.
I searched the web for it and found the solution that the others claimed it works fine. It is just add a '--disable-dev-shm-usage' to chrome options. But it still error.
ff.js
const webdriver = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome');
const driver = new webdriver.Builder()
// The "9515" is the port opened by chrome driver.
.usingServer('http://localhost:9515')
.withCapabilities({
chromeOptions: {
args: ['--headless', '--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage', 'start-minimized'],
// Here is the path to your Electron binary.
binary: './dist_electron/mac/myapp.app/Contents/MacOS/myapp'
}
})
.setChromeOptions(new chrome.Options().addArguments('--remote-debugging-port=7070'))
.forBrowser('electron')
.build()
driver.quit()
package.json
"devDependencies": {
"#types/chai": "^4.1.0",
"#types/mocha": "^5.2.4",
"#vue/cli-plugin-babel": "^3.5.0",
"#vue/cli-plugin-e2e-nightwatch": "^3.6.0",
"#vue/cli-plugin-eslint": "^3.5.0",
"#vue/cli-plugin-typescript": "^3.5.0",
"#vue/cli-plugin-unit-mocha": "^3.5.0",
"#vue/cli-service": "^3.5.0",
"#vue/eslint-config-standard": "^4.0.0",
"#vue/eslint-config-typescript": "^4.0.0",
"#vue/test-utils": "1.0.0-beta.29",
"babel-eslint": "^10.0.1",
"babel-plugin-istanbul": "^5.1.3",
"bootstrap": "^4.3.1",
"chai": "^4.1.2",
"chromedriver": "^73.0.0",
"copy-webpack-plugin": "^5.0.2",
"electron": "^4.0.0",
"electron-rebuild": "^1.8.4",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"jquery": "^3.4.0",
"mocha": "^6.1.4",
"mochawesome": "^3.1.2",
"node-sass": "^4.9.0",
"nyc": "^14.0.0",
"popper.js": "^1.15.0",
"sass-loader": "^7.1.0",
"selenium-webdriver": "^4.0.0-alpha.1",
"ts-node": "^8.1.0",
"ts-protoc-gen": "^0.9.0",
"typescript": "^3.2.1",
"vue-cli-plugin-electron-builder": "^1.2.0",
"vue-template-compiler": "^2.5.21",
"vuex-module-decorators": "^0.9.8",
"webdriverio": "^5.8.3"
}
ps. I've tried with ChromeDriver#74.x.x, it still resulted same error.
Actually, I've tried with Selenium RobotFramework and still found the same error. I think it was something wrong with my test writing or some settings. (I'm not good in test tool.)
Just for information
mytest.robot
*** Settings ***
Library Selenium2Library
Variables vars.py
*** Test Cases ***
Foohaha
Create Webdriver Remote desired_capabilities=${binary_location} command_executor=http://localhost:9515
Log To Console ${item.get_attribute('innerHTML')}
[Teardown] Close All Browsers
P.s. The reason why not spectron is the tester I have only use the Selenium.

After I tried almost recommended testing library. I ended up with testcafe. Setting the pref app path to my distributed app's binary then set the page to open as html file in test file. The primary path was a default value.
This is how I set it up.
.testcafe-electron-rc
{
"mainWindowUrl": "app://./index.html",
"electronPath": "/Users/xxx/Documents/ProjectFolder/dist_electron/mac/my-lovely-app.app/Contents/MacOS/my-lovely-app",
"openDevTools": "true"
}
package.json
"scripts": {
...
"cafe": "testcafe \"electron:/Users/xxx/Documents/ProjectFolder/.testcafe-electron-rc\" \"/Users/xxx/Documents/ProjectFolder/tests/e2e/specs/testcafe.js\""
},
"devDependencies": {
...
"selenium-webdriver": "^4.0.0-alpha.1",
"testcafe": "^1.1.4",
"testcafe-browser-provider-electron": "0.0.8"
}
testcafe.js
import { Selector } from 'testcafe';
fixture(`Index page`)
.page('/Users/xxx/Documents/ProjectFolder/dist_electron/bundled/index.html');
test('Body > Paragraph contains "Hello World!"', async testController => {
const paragraphSelector = await new Selector('#nav > a.router-link-exact-active.router-link-active');
const txt = await new Selector('#app > div.auth-page > div > div > div > form > fieldset:nth-child(1) > input');
await testController.click(paragraphSelector)
.typeText(txt, 'Peter Parker');
// .expect(paragraphSelector.innerText).eql("Login");//.eql('Login');
});
Hope this will help someone.

Related

Microsoft Signal R not able to establish connnection in Prodution build with next js

The negotiation URL is not correctly set while initiating Signal R connection in next js PRODUCTION build (using yarn build command). It's works fine with development build (using yarn dev command)
Local build signal R log - Sending negotiation request to given URL while initiating Signalr
Production build Signal R log- Sending negotiation request is missing the actual URL that is passed while initiating Signalr,
Throws error _app-981b32fff10f13a9.js:2 POST http://localhost:3000/register/pre-fetch?negotiateVersion=1 405 (Method Not Allowed)
here negotiation request URL is changed to " http://localhost:3000/register/pre-fetch?negotiateVersion=1" which is a component path from where signal R initiated, this should be: https:/{{SignalrURL}}/negotiate?negotiateVersion=1.
signal.ts file
import * as signalR from '#microsoft/signalr';
const conn = new signalR.HubConnectionBuilder()
.withUrl('SignalrURL',
{ accessTokenFactory: () => localStorage.getItem('token') })
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Debug)
.build()
.start();
package.json
"dependencies": {
"#deere/fuel-react": "^3.0.0",
"#microsoft/signalr": "^7.0.0",
"#mui/icons-material": "^5.10.14",
"#mui/x-data-grid": "^5.17.14",
"#reduxjs/toolkit": "^1.9.1",
"#sentry/nextjs": "^7.23.0",
"applicationinsights": "^2.3.6",
"axios": "^1.2.0",
"moment": "^2.29.4",
"moment-timezone": "^0.5.38",
"net": "^1.0.2",
"next": "13.0.4",
"next-auth": "^4.18.4",
"nextjs-redirect": "^6.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-intl": "^6.2.1",
"react-redux": "^8.0.5",
"react-test-renderer": "^18.2.0",
"react-toastify": "^9.1.1",
"rxjs": "^7.6.0",
"tls": "^0.0.1",
"v8": "^0.1.0"
},

RadioGroupButton doesn't seem to work with React Starter Kit

Here's a gif of it:
http://www.giphy.com/gifs/3oKIP7arhKhNzNzytq
As you can see, whenever I click on it, it doesn't select.
Here's my exact code which is working in webpack:
https://www.webpackbin.com/bins/-KoaaPYxDno695fiUBMn
But in my starter kit environment, it doesn't seem to work. However, checkboxes seem to work. Any ideas?
"react": "^15.5.4",
"react-dom": "^15.5.4",
"material-ui": "^0.18.6",
EDIT: I also have react-tap-event-plugin and I've called it at the top of my client.js file. Also tried on the top of my Location.js file.
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
Here's my full dependency list:
dependencies": {
"apisauce": "^0.14.0",
"babel-polyfill": "^6.23.0",
"bluebird": "^3.5.0",
"body-parser": "^1.17.2",
"classnames": "^2.2.5",
"cookie-parser": "^1.4.3",
"core-js": "^2.4.1",
"express": "^4.15.3",
"express-graphql": "^0.6.6",
"express-jwt": "^5.3.0",
"graphql": "^0.10.3",
"history": "^4.6.3",
"isomorphic-style-loader": "^2.0.0",
"jsonwebtoken": "^7.4.1",
"material-ui": "^0.18.6",
"node-fetch": "^1.7.1",
"normalize.css": "^7.0.0",
"passport": "^0.3.2",
"passport-facebook": "^2.1.1",
"pretty-error": "^2.1.1",
"prop-types": "^15.5.10",
"query-string": "^4.3.4",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-tap-event-plugin": "^2.0.1",
"sequelize": "^4.2.1",
"serialize-javascript": "^1.3.0",
"source-map-support": "^0.4.15",
"sqlite3": "^3.1.8",
"universal-router": "^3.2.0",
"whatwg-fetch": "^2.0.3"
},
You are most probably missing the react-tap-event-plugin.
Add it with npm install -save react-tap-event-plugin
I strugged with this problem for couple of days and found a solution. See if it works for you
Why was it not working?
If you look closely at the backend code of RadioButton you'll realize that it is actually similar to the Checkbox. I realized the problem was not only with RadioButtons but the checkbox was also not working (while the toggles were working fine).
I took my source code and ran it using CRA (Create React App) and it the RadioButtons were working perfectly. For RSK (React Starter Kit) the first suspect which was different was BrowserSync. I dug a little deeper and found that there is a config in BrowserSync for Ghost clicks which was to be turned off. You can read more about it here
https://github.com/callemall/material-ui/issues/2983
To turn off Ghost mode in your start script, goto /tools/start.js in your RSK Project folder and change config to
browserSync.create().init(
{
// https://www.browsersync.io/docs/options
server: 'src/server.js',
ghostMode: false,
middleware: [server],
open: !process.argv.includes('--silent'),
...(isDebug ? {} : { notify: false, ui: false }),
},
(error, bs) => (error ? reject(error) : resolve(bs)),
),

How do I fix flow error "TouchHistoryMath. Duplicate module provider"

I'm configuring a new project and have started importing some libraries when I get the following flow error. What does this error mean and how do I diagnose and fix? This is a react native project and I recently added the subscriptions-transport-ws library.
Launching Flow server
Spawned flow server (pid=13272)
node_modules/react-native/Libraries/Renderer/src/renderers/shared/stack/event/eventPlugins/TouchHistoryMath.js:0
TouchHistoryMath. Duplicate module provider
current provider. See: node_modules/react-native-gesture-responder/library/TouchHistoryMath.js:0
package.json
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"flow": "node_modules/.bin/flow",
"flow-stop": "node_modules/.bin/flow stop"
},
"dependencies": {
"#shoutem/ui": "^0.10.9",
"apollo-client": "0.8.0",
"graphql": "^0.9.1",
"graphql-tag": "^1.2.4",
"lodash": "^4.17.4",
"react": "~15.4.0",
"react-apollo": "^0.10.1",
"react-native": "0.41.2",
"react-native-lock": "^0.4.0",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-actions": "^1.2.1",
"redux-persist": "^4.4.0",
"redux-thunk": "^2.2.0",
"subscriptions-transport-ws": "^0.5.1"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"babel-jest": "18.0.0",
"babel-preset-react-native": "1.9.1",
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "6.9.0",
"flow-bin": "0.37.0",
"jest": "18.1.0",
"react-test-renderer": "~15.4.0"
},
"jest": {
"preset": "react-native"
}
I believe it is a bug caused by two modules having the same name. A workaround that solved the issue for me was to tell Flow to ignore one of the modules. In other words, add one (or both) of the following lines under the [ignore] section of your .flowconfig file:
.*/node_modules/react-native/Libraries/Renderer/src/renderers/shared/shared/event/eventPlugins/TouchHistoryMath.js
.*/node_modules/react-native-gesture-responder/library/TouchHistoryMath.js
Note: the first of these files seems to be part of the core react-native library, while the second comes from a dependency used by #shoutem/ui. I'm not sure if there's any side effects with excluding any of these files from Flow.
You should comment these lines.
# UNSUPPORTED - HASTE
#module.system=haste
#module.system.haste.use_name_reducers=true
Reference: https://github.com/facebookarchive/node-haste
Unsupported/Archived Facebook no longer uses node-haste, and this
project was not being maintained.

How to serve static assets like json file in webpack dev server?

I am building a react app. I have used yeoman to generate the react app structure. I am using webpack to bundle all js files. My package.json is -
{
"dependencies": {
"axios": "^0.15.0",
"classnames": "^2.2.5",
"es6-shim": "^0.35.0",
"react": "^15.0.1",
"react-dom": "^15.0.1",
"react-mdl": "^1.7.2",
"react-redux": "^4.4.5",
"react-router": "^2.4.0",
"redux": "^3.5.1",
"todomvc-app-css": "^2.0.4"
},
"devDependencies": {
"autoprefixer": "^6.2.2",
"babel-core": "^6.13.0",
"babel-eslint": "^6.0.2",
"babel-loader": "^6.2.0",
"babel-plugin-istanbul": "^2.0.1",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.2.0",
"babel-preset-react": "^6.1.18",
"browser-sync": "^2.9.11",
"browser-sync-spa": "^1.0.3",
"css-loader": "^0.23.1",
"del": "^2.0.2",
"es6-shim": "^0.35.0",
"eslint": "^3.2.2",
"eslint-config-xo-react": "^0.7.0",
"eslint-config-xo-space": "^0.12.0",
"eslint-loader": "^1.3.0",
"eslint-plugin-babel": "^3.1.0",
"eslint-plugin-react": "^5.0.1",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"file-loader": "^0.9.0",
"gulp": "gulpjs/gulp#4ed9a4a3275559c73a396eff7e1fde3824951ebb",
"gulp-filter": "^4.0.0",
"gulp-hub": "frankwallis/gulp-hub#d461b9c700df9010d0a8694e4af1fb96d9f38bf4",
"gulp-sass": "^2.1.1",
"gulp-util": "^3.0.7",
"html-webpack-plugin": "^2.9.0",
"jasmine": "^2.4.1",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-junit-reporter": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-phantomjs-shim": "^1.1.2",
"karma-webpack": "^1.7.0",
"node-sass": "^3.4.2",
"phantomjs-prebuilt": "^2.1.6",
"postcss-loader": "^0.8.0",
"react-addons-test-utils": "^15.0.1",
"react-hot-loader": "^1.3.0",
"sass-loader": "^3.1.2",
"style-loader": "^0.13.0",
"webpack": "2.1.0-beta.20",
"webpack-dev-middleware": "^1.4.0",
"webpack-hot-middleware": "^2.6.0"
},
"scripts": {
"build": "gulp",
"serve": "gulp serve",
"serve:dist": "gulp serve:dist",
"test": "gulp test",
"test:auto": "gulp test:auto"
},
"eslintConfig": {
"root": true,
"env": {
"browser": true,
"jasmine": true
},
"extends": [
"xo-react/space",
"xo-space/esnext"
]
}
}
I am using axios to make http requests. Presently, I have not coded a server to return a json data. Hence, to test the app's functionality, I want to serve static json data from a json file.
How can I achieve this ?
Since this setup is running a web-server, I hope a json file can be served using something like - axios.get('http://localhost:3000/user.json').
If you're starting your app from the Facebook's 'create-react-app' instructions found here: https://facebook.github.io/react/docs/installation.html
Then I found an easy way to be able to access JSON files from the URL without having the React Router get in the way and intercept the request.
All you have to do is in your index.js of that 'create-react-app' scaffolding, add something like this as the very first line:
import './myJsonFile.json';
And that's it, as afterwards going to:
http://localhost:3000/myJsonFile.json
would correctly fetch the file without React router interfering in the lookup.
(maybe it wasn't exactly your question as you've used a different way to generate the app, but this would be an answer for those who use the 'create-react-app' as a base).
You can use the webpack file-loader to have webpack serving that file as if it was any other static files, e.g. an image.
You can try with this in your "main" (entrypoint) file:
require("file-loader?name=api/[name].[ext]!./user.json");
This require is just needed to tell webpack to "emit" that file in the output destination, otherwise it doesn't know anything about it.
You also need to install the file-loader:
npm install --save-dev file-loader
Then with webpack-dev-server you should be able to access that file from http://localhost:8080/api/user.json (replace localhost:8080 according to your webpack dev server config).
However, if you need to stub a json api, I'd rather use something like these:
https://www.npmjs.com/package/json-server
https://www.npmjs.com/package/dyson
that are more flexible and can handle more advanced thing like serving the response with the right content type, testing cross domain issues, JSONP, etc.
If you want something simpler, you can use this: https://www.npmjs.com/package/superstatic to simply serve static files,
or even simpler, check out how these one-liners to start a simple http server to serve your static json files:
https://gist.github.com/willurd/5720255

electron: Can't load http://localhost:8080

I can load http://localhost:8080 from chrome, but It occur error with win.loadURL('http://localhost:8080/');, and I don't know why.
Error code :
Failed to load resource:localhost:8080 net::ERR_EMPTY_RESPONSE,
My code
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const url = require('url');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
function load() {
mainWindow.loadURL('http://127.0.0.1:8080');
}
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadURL('http://127.0.0.1:8080');
mainWindow.loadFile('index.html');
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
});
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
});
// In this file you can include the rest of your app's specific main process
And this is package.json
{
"version": "1.0.0",
"name": "idena-pocket",
"private": true,
"main": "public/main.js",
"scripts": {
"dev": "export NODE_ENV=development && webpack-dev-server --https --host 127.0.0.1 --open",
"electron-dev": "concurrently \"BROWSER=none npm run dev\" \"electron .\"",
"electron-dev1": "concurrently \"BROWSER=none\" \"electron .\"",
"electron-dev2": "concurrently \"BROWSER=none npm run dev\" \"wait-on https://10.0.2.2:8080/ && electron .\"",
"electron-package": "./node_modules/.bin/electron-builder -c.extraMetadata.main=build/start-electron.js",
"preelectron-package": "npm run build",
"i18-scanner": "i18next-scanner src/**/*.{js,jsx,ts,tsx,html}",
"format": "prettier-standard --format"
},
"dependencies": {
"react-scripts": "0.8.5",
"bip39": "^3.0.2",
"concurrently": "^6.0.2",
"connected-react-router": "^6.8.0",
"crypto-js": "^4.0.0",
"electron": "^12.0.6",
"electron-builder": "^22.11.1",
"electron-is-dev": "^2.0.0",
"history": "^4.10.1",
"i18next": "^19.4.4",
"i18next-browser-languagedetector": "^4.1.1",
"i18next-scanner": "^2.11.0",
"idena-js": "1.1.5",
"react": "^16.13.1",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^16.13.1",
"react-hook-form": "^5.5.3",
"react-i18next": "^11.4.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-tooltip": "^4.2.5",
"redux": "^4.0.5",
"styled-components": "^5.0.1",
"sweetalert": "^2.1.2",
"wait-on": "^5.3.0"
},
"devDependencies": {
"#types/react": "^16.9.25",
"#types/react-dom": "^16.9.5",
"#types/react-redux": "^7.1.7",
"#types/react-router-dom": "^5.1.3",
"#types/styled-components": "^5.1.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.4.2",
"file-loader": "^6.0.0",
"html-webpack-plugin": "^3.2.0",
"pre-commit": "^1.2.2",
"prettier-standard": "^16.3.0",
"react-hot-loader": "^4.12.20",
"ts-loader": "^6.2.1",
"typescript": "^3.8.3",
"url-loader": "^4.1.0",
"webpack": "^4.43.0",
"webpack-bundle-analyzer": "^3.7.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0",
"workbox-webpack-plugin": "^5.1.3"
},
"pre-commit": [
"format"
]
}

Resources