Unable to establish a connection with the SafariDriver extension - selenium

I have been running e2e tests in an AngularJS web-app using protractor, testing on Chrome and Firefox. When adding safari to my array, the following is displayed:
"Unable to establish a connection with the SafariDriver extension"
I have found a way to solve this locally but as we are using Codeship to automate our builds, I need a way to solve it rather than having to manually add the driver to selenium and enable in Safari.
I am using selenium 2.43.1
config:
exports.config = {
baseUrl: 'http://localhost:9001',
multiCapabilities: [{
'browserName': 'chrome'
}, {
'browserName': 'firefox'
}, {
'browserName': 'safari'
}],
specs: ['e2e/app.js']
};
package.json:
{
"name": "livingthevalues",
"version": "0.0.0",
"dependencies": {
"express": "^4.9.7",
"gzippo": "^0.2.0",
"bower": "^1.3.8",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-autoprefixer": "^0.7.3",
"grunt-concurrent": "^0.5.0",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-compass": "^0.7.2",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-connect": "^0.7.1",
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-cssmin": "^0.9.0",
"grunt-contrib-htmlmin": "^0.3.0",
"grunt-contrib-imagemin": "^0.8.1",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-filerev": "^0.2.1",
"grunt-google-cdn": "^0.4.0",
"grunt-newer": "^0.7.0",
"grunt-ng-annotate": "^0.3.0",
"grunt-svgmin": "^0.4.0",
"grunt-usemin": "^2.1.1",
"grunt-wiredep": "^1.7.0",
"jshint-stylish": "^0.2.0",
"load-grunt-tasks": "^0.4.0",
"time-grunt": "^0.3.1"
},
"devDependencies": {
"chai": "^1.9.2",
"chai-as-promised": "^4.1.1",
"cucumber": "^0.4.4",
"grunt-karma": "^0.9.0",
"grunt-protractor-runner": "^1.1.4",
"karma": "^0.12.17",
"karma-chrome-launcher": "^0.1.4",
"karma-jasmine": "^0.1.5",
"karma-junit-reporter": "^0.2.2",
"karma-mocha": "^0.1.6",
"karma-phantomjs-launcher": "^0.1.4",
"protractor": "^1.3.1",
"protractor-cucumber": "^0.1.2",
"sinon": "^1.11.0"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test",
"pree2e": "./node_modules/protractor/bin/webdriver-manager update",
"e2e": "grunt test:e2e"
}
}
commands run by ci:
Exporting Environment
0 min 2 sec
git clone --branch 'commentBox' --depth 50 git#github.com:MyTeam/myrepo.git ~/src/github.com/MyTeam/myrepo
0 min 1 sec
cd clone
0 min 1 sec
git checkout -qf 2ec65e3b32971d0f7f9de948c40f019f0629adea
0 min 1 sec
Preparing Dependency Cache
0 min 10 sec
Preparing Virtual Machine
0 min 5 sec
rvm use 2.0.0-p195
0 min 5 sec
bundle install
0 min 2 sec
nvm install 0.10.25
0 min 2 sec
nvm use 0.10.25
0 min 1 sec
npm install
0 min 7 sec
bower instal
0 min 7 sec
npm test
0 min 10 sec
npm run e2e
Thanks - seems like such a simple thing to do but can't understand why it isn't working.

On Mac, The Selenium SafariDriver extension you used to have to install is now depreciated. On El Capitan & Sierra Apple provides it's own Safaridriver. Uninstall previous safaridriver extension (if you had installed it) and enable the new safaridriver, excerpt from link 2:
Ensure that the Develop menu is available. It can be turned on by opening Safari preferences (Safari > Preferences in the menu bar), going to the Advanced tab, and ensuring that the Show Develop menu in menu bar checkbox is checked.
Enable Remote Automation in the Develop menu. This is toggled via
Develop > Allow Remote Automation in the menu bar.
Authorize safaridriver to launch the webdriverd service which hosts
the local web server. To permit this, run /usr/bin/safaridriver once
manually and complete the authentication prompt. e.g. in terminal: /usr/bin/safaridriver -p 8000
Also, You need to be running Selenium 3.0 + (support started at 3.0.0-beta1) to use the new safari driver.
Note:
If you still have trouble maybe check the Addendum at bottom of the 2nd link. Another caveats I ran into, the new safaridriver only supports one session so maxSessions=# is no longer supported. Also, if you use npm selenium-standalone install you can update selenium version like so.
selenium-standalone install --version=3.0.1 --baseURL=https://selenium-release.storage.googleapis.com
And then boot hubs and nodes with the --version=3.0.1 flag.

I'm wrestling with this exact issue trying to automate our tests against Safari 7.1. My research so far leads me to believe that with Safari 7.1, a new security model was put into place to make extensions more secure. Here is a related thread fwiw. I have tried using the mvn command line to install the SafariDriver extension but it fails to do so. I've tried running a simple command line to open Safari with the extension as a parameter but then you are prompted to enable/install it. (no good for unattended flows). Another hack that was suggested was to go directly to the plist file that Safari uses for preferences/extensions but I could not find it on Mac 10.10. I'm quite anxious to know the answer here.

I'm using Windows 7.
Prerequisite: Install Safari on Windows
Go to http://docs.seleniumhq.org/download/
Scroll down -> Go to the section "SafariDriver" and download "SafariDriver.safariextz"
Double click on "SafariDriver.safariextz" (previously downloaded)
Safari would open with a pop up containing "Install" button -> Click Install button
Now go to Preferences of Safari and you would see WebDriver (in my case WebDriver 2.48.0) is installed (Enable WebDriver checkbox is checked))
It's now time to instantiate SafariDriver and get the desired URL as below:
WebDriver driver = new SafariDriver();
driver.get("https://www.packtpub.com/web-development/mastering-selenium-testing-tools-video");

Related

IDE does not recognize Jest and its functions

I have a basic react-native/expo template app. I have added jest-expo and react-test-renderer in the dev dependencies, and also have updated package.json like documented in the expo docs for testing.
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
...
"test": "jest"
},
"dependencies": {
"expo": "~41.0.1",
...
"react": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
},
"devDependencies": {
"#babel/core": "^7.9.0",
"#testing-library/jest-native": "^4.0.1",
"#testing-library/react-native": "^7.2.0",
"jest-expo": "^41.0.0",
"react-test-renderer": "^17.0.2"
},
"private": true,
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
],
"setupFilesAfterEnv": [
"#testing-library/jest-native/extend-expect"
]
}
}
I have also added React Native Testing Library to test the UI. And the tests are running fine.
But the problem is that WebStorm IDE is not recognizing Jest and its functions.
Could you please help me figure this out?
Update
As per the comments, I tried installing the Typescript Jest types definition through the Settings config and also tried installing with yarn/npm . But this didn't help.
Another Update
However, If I uncheck the project's node_modules libraries, the Jest type definitions picks up.
But doing so, other types of node_modules doesn't work!
In Preferences - Languages & Frameworks - JavaScript - Libraries, press Download, then Select jest from the list, press Download and Install. If it didn't work try npm i #types/jest in your Local Folder.
Have you tried this WebStorm configuration?
You might have noticed that some of the global Jest methods (like
describe and beforeEach) in JavaScript files are marked as unresolved
in the editor. To fix that, install the TypeScript type definition
files for Jest: Go to Preferences | Languages & Frameworks |
JavaScript | Libraries, click Download on the right-hand side of the
dialog, then search for Jest in the list and click Install. Or add
#types/jest to devDependencies in project’s package.json.

Vue npm run serve starts on random port

I'm trying to run Vue on port 8080, but can't get that to work. I just created a brand new project with vue create . and ran it with npm run serve, which starts the app on a random port.
First attempt
Run npm run serve without any additional configuration
$ npm run serve
> vue-demo#0.1.0 serve /Users/ne/projects/vue-demo
> vue-cli-service serve
INFO Starting development server...
Starting type checking service...
Using 1 worker with 2048MB memory limit
98% after emitting CopyPlugin
DONE Compiled successfully in 4294ms 3:21:35 PM
No type errors found
Version: typescript 3.5.3
Time: 4267ms
App running at:
- Local: http://localhost:20415/
- Network: http://192.168.178.192:20415/
Note that the development build is not optimized.
To create a production build, run npm run build.
So first I checked to see if another app is running on that port with lsof -i :8080 but that gave no results.
Second attempt
So the second attempt was to force the port via the cli with npm run serve -- --port 8080, which still started the app on a random port, but no errors in the browser console.
Third attempt
Next I tried to configure the application in vue.config.js.
module.exports = {
devServer: {
open: process.platform === 'darwin',
host: 'localhost',
port: 8080, // CHANGE YOUR PORT HERE!
https: false,
hotOnly: false,
},
};
Which didn't work either and even throws an exception in the browser console:
15:25:20.889 :8080/sockjs-node/info?t=1566048320873:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:20.910 client?81da:172 [WDS] Disconnected!
close # client?81da:172
15:25:21.982 :8080/sockjs-node/info?t=1566048321978:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:23.079 :8080/sockjs-node/info?t=1566048323075:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:25.097 :8080/sockjs-node/info?t=1566048325091:1 Failed to load resource: net::ERR_CONNECTION_REFUSED
15:25:29.151 VM14:1 GET http://localhost:8080/sockjs-node/info?t=1566048329145 net::ERR_CONNECTION_REFUSED
package.json
I added package.json, since I might be missing something here.
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"
},
"dependencies": {
"core-js": "^2.6.5",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
"vue-property-decorator": "^8.1.0",
"vue-router": "^3.0.3",
"vuex": "^3.0.1"
},
"devDependencies": {
"#types/jest": "^23.1.4",
"#vue/cli-plugin-babel": "^3.10.0",
"#vue/cli-plugin-eslint": "^3.10.0",
"#vue/cli-plugin-typescript": "^3.10.0",
"#vue/cli-plugin-unit-jest": "^3.10.0",
"#vue/cli-service": "^3.10.0",
"#vue/eslint-config-airbnb": "^4.0.0",
"#vue/eslint-config-typescript": "^4.0.0",
"#vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"node-sass": "^4.9.0",
"sass-loader": "^7.1.0",
"ts-jest": "^23.0.0",
"typescript": "^3.4.3",
"vue-template-compiler": "^2.6.10"
}
}
What am I missing?
Note: This issue is specific to node-portfinder v1.0.22. It was resolved in v1.0.23 that is a retag of v1.0.21.
This seems a feature in portfinder that used random series to allocate an available port.
Trying:
const portfinder = require('portfinder');
portfinder.basePort=8080
portfinder.getPortPromise().then((port) => { console.log(port) })
return something like:
9567
Even if port 8080 is available.
The behaviour change recently in this commit. Before the port were try increasing from basePort to highestport. It comes with the release v1.0.22
Option1: Patching
In order to use the port 8080, I patched the file node_modules/#vue/cli-service/lib/commands/serve.js adding line 322 portfinder.highestPort = portfinder.basePort + 1
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
portfinder.highestPort = portfinder.basePort + 1
const port = await portfinder.getPortPromise()
Option2: Install portfinder previous to the behaviour change
Another way to workaround waiting for portfinder/vue-cli to choose a solution is to install old portfinder with :
npm install portfinder#1.0.21
You can temporarily rollback portfinder by placing
"resolutions": {
"#vue/cli-service/portfinder": "1.0.21"
}
in your package.json file and run yarn install afterwards.
Most of time the error occurred when something is running on the same port. But as you mentioned above you have checked it out and there is nothing on it.
Have you tried to restart or shutdown your system and run the server again if not give it a try some of the time its worked for me.
Secondly it would be help full if you share the object of Scripts in package.json.
I have gone through your issue and found this article may be this will help you out. Let me know if the error still exists.

New react-native project won't load on iOS or android

On Mac OS X 10.14
Creating a new project with:
react-native init project
It builds the new project with the following list: https://pastebin.com/ED8qd0Ee
I run npm install to update anything.
Then I run react-native run-android The project builds and sends to device but I get an error there and the MetroBundler opens but all I get is Process terminated. Press to close the window.
Im not sure what the issue is? I had no problem running a test app a week ago. I get back to it today and this.
On iOS, the app never builds on the device. The metro bundler again terminates immediately and the process reads off an infinite list of errors
react-native init project this command create the project with latest versions so try to create project with previous versions like this react-native init newproject --version react-native#0.54.4
you can choose any version here is mine
"react": "16.6.3",
"react-native": "^0.57.8",
"devDependencies": {
"#babel/runtime": "^7.0.0",
"redux-devtools-extension": "^2.13.5",
"schedule": "^0.4.0",
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.51.0",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
also check this code in .babelrc file
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
Run this command in your project rm -r node_modules it will delete node_modules folder in your project and change your package.json file and Run Command npm install.

Hot Reload not working in react-native android

I tried it on windows 10 and Ubuntu 16.04. In both cases the Hot Reload only works with changes in jsx, but not, when I change a variabel or function or something else in javascript. The Hot Reload is enabled. Live reload is disabled. When I save a change in the Visual Studio Code Editor, the virtual Device (android studio) reloads, but the changes are not there. The same on physical device in EXPO App.
First I didn`t install watchman. Hot Relaod not working. After installing it Hot Reload not working too.
I startet the app with create-react-native-app. It is not ejected.
package.json:
{
"name": "NativeReduxSaga",
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "25.0.0",
"react-native-debugger-open": "^0.3.17",
"react-native-scripts": "1.11.1",
"react-test-renderer": "16.2.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js",
"postinstall": "rndebugger-open --expo"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"#redux-offline/redux-offline": "^2.3.2",
"expo": "^25.0.0",
"prop-types": "^15.6.1",
"react": "16.2.0",
"react-native": "0.52.0",
"react-native-autocomplete-input": "^3.5.0",
"react-navigation": "^1.5.2",
"react-redux": "^5.0.7",
"redux": "^3.7.2",
"redux-devtools-extension": "^2.13.2",
"redux-logger": "^3.0.6",
"redux-observable": "^0.18.0",
"redux-promise-middleware": "^5.0.0",
"redux-saga": "^0.16.0",
"redux-thunk": "^2.2.0",
"rxjs": "^5.5.7"
}
}
watchman version
{
"version": "4.9.1",
"buildinfo": "94e66865386e844f2cffe52e355a94c96562d2e3 2018-03-12T19:58:02.0000000Z"
}
node version
v6.13.1
I read in some articles here, that it could help on Windows, to raise the MAX_WAIT_TIME. But I don´t have a \node_modules\react-native\node_modules\node-haste\lib\FileWatcher\ index.js file.
And why isn´t it working on Ubuntu , too?
Do I really need the watchman? How should it be configured? My .watchmanconfig file is an empty object like {}.
Is Hot Reload usually working with create-react-native-app?
Does anybody know what I can try here, to get the hot reload working?
Thanx for an help!
Actually there's a difference between Hot and Live Reloading.
Hot Reloading is instant reload while keeping the state of your application intact. However, it only works inside the render method and is only triggered on extensions of classes React.Component and Component
As in:
class A extends Component ...
class B extends React.Component ...
Live Reload on the other hand, rebuilds your application and discards your application state. It includes everything, from variables and methods to the simplest of string. That's why one will always start from the start screen of the application (because the state is lost).
Hope it helps!
Deleting the git index.lock file worked for me
rm -rf .git/index.lock
in android go to your MainApplication.Java
search for
#Override
public boolean getUseDeveloperSupport() {
return true;
}
Make sure it returns true. It might be the issue
I did the following steps to resolve this issue:
mkdir android/app/src/main/assets
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Shake android device or cmd + d in the simulator you will get a menu.
Once enable and disable Hot reload.
clear whatever the IP address you are using in Dev settings -> Debugging -> Debug server host & port for device.
Enable Hot reloading.
In terminal go to your project directory -> react-native start
react-native run-android or run it directly in your android studio.
Alternative solution:
"scripts": {
- "start": "react-native-scripts start",
+ "start": "DEBUG=true react-native-scripts start",
},
To have it work, you should make sure this file wasn't changed:
// ./android/app/src/main/java/com/cubyn/storage/MainApplication.java
...
#Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
...
IMHO it's a better solution because it will be enabled only during dev, and not when bundled for production.
For me the problem was with the AndroidX, basically some time you need to migrate to AndroidX due to the react-native old versions
just open your project in the Android Studio
Refactor -> Migrate to Android X ... and flow the instructions
and don't avoid to make backup when it will be promoted for save side
For anyone experiencing this problem when using WSL 2, the files need to exist inside of the Linux subsystem instead of inside any mounted Windows folders for the file watching to work properly. Taken from this post on Reddit:
They changed the file sharing protocol, from using they own custom developed protocol to using the 9P protocol, which at this time might not support file changes event.
I believe you can fix this issue by putting your code on the Linux file system (ex: in your user's home directory), and access these files through the WSL share, \wsl$\DISTRO_NAME from Windows.
In the Windows explorer, if you go to \wsl$, you should see all your WSL Linux distros installed and can access all the files on their file systems.
I think this is strait forward
Also dont forget to run npm start in your text editor and not outside editor like git bash
Make sure you don't have an index.lock file in your .git directory :) Deleting it could solve your issue.

my cucumber feature step always stop running when occuring the time out & element not clickable issue

My cucumber feature step always stops running when occurring the time out & element not clickable issue.
when running my automation script of couple feature file together, my cucumber feature step always stops running when met the issue mentioned above, this causes me can't generate the final status report. can anyone help with this issue? is that because my cucumber version is too old?
below is my package.json file
"dependencies": {
"chai": "4.0.2",
"chai-as-promised": "7.1.1",
"cucumber": "^2.3.0",
"cucumber-html-reporter": "^2.0.0",
"moment": "2.18.1",
"protractor": "5.1.1",
"protractor-cucumber-framework": "^3.1.1",
"q": "^1.5.0",
"simple-oauth2": "^1.2.0",
"cucumber-junit": "^1.7.0"
and below is the snapshot of my error.
enter image description here
Can you please set the ignoreUncaughtExceptions flag to true in your protractor configuration like mentioned below:
exports.config = {
seleniumAddress: env.seleniumAddress,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
ignoreUncaughtExceptions: true,
}