Automate Protractor / Selenium / Webdriver command - javascript

How can i start my localhost server with node app.js, run webdriver-manager start, and protractor conf.js in one command.
Each of these commands take place in a different folder.
I want to streamline this process.
I have a written an alias that executes each command in their respective folders.
Problem is, each of these commands launch a server, and the terminal enters non-canonical mode which causes an issue.
I have tried adding & to the end of each command, but this did not work.

Solve it via a task management tool like grunt or gulp.
Here is the list of plugins that might be useful in your case:
grunt-protractor-runner
grunt-contrib-connect
grunt-contrib-watch
See also:
Testing With AngularJS Part 5: Protractor and Grunt
Integrating Protractor with Yeoman via Grunt

Related

How to deploy angular 7 project directly to my webserver, so that i shouldn't migrate my dist folder always after deployment?

Currently, I am deploying my Angular 7 Project by using FileZilla to migrate my local files from ./dist folder to server public_HTMl. This is a quite tides job to carry in a daily basis, so I want to deploy my code directly to the server, when I hit ng build --prod then those compiled files have to be migrated directly to the server. Do anybody here who can help me to solve this problem?
To get rid of this problem I have tried lots of steps:
I was using bitbucket pipelines to execute my code, it came to be costly and I cannot run it as well, It took several hours but cannot give output for me.
I also tried by using new Git Repository even it's a good way but cannot give me the solution because when I deploy my code locally it creates a new folder every time while I execute a command.
So, I want to get help and deploy this code directly to the server that is going to host my application. Thank you all and hope all of you provide me good tips regarding this problem.
You can do it in the simple way. Create basic bash/sh script or windows executable and use rsync to do this automatically:
deploy.sh:
#!/bin/bash
ng build --prod
rsync -arvt ./dist remoteuser#remotehost:/var/www/remotedirectory
To avoid entering login and password every time add RSA public key to your remote machine(trusted host). You can combine this solution with Bitbucket pipelines, when the free plan ends I run this script manually from my developer machine.
bitbucket-pipelines.yml:
image: mycustomimage:latest
pipelines:
default:
- step:
name: Build and deploy to production
caches:
- node
deployment: production
script:
- npm install
- npm install -g #angular/cli
- ng config -g cli.warnings.versionMismatch false
- ./deploy.sh
Instead of a simple script you can use some more complex solution like Capistrano, Shipit or some other more advanced tool. All depends on your needs...
The simplest solution is always the best :)

bash / zsh protractor: auto run protractor's CLI commands in --elementExplorer mode

how it possible to write a bash script that run Protractor and send some init commands to it, like :
"prx.sh"
protractor --elementExplorer
browser.get('http://www.angularjs.org');
look simple, but Protractor block the second command by it internal loop
we can do:
protractor --elementExplorer &
but then we need some way to send the next command to protractor SDIN
e.g
I know I can use :
protractor --baseUrl 'http://www.angularjs.org' --elementExplorer
to solve above example, but I'm interested in general how to run environement command for init some variables, so it will be more easy to play with them in the interactive mode
I thinks it is general qustions about bash\zsh

Debugging node js in Webstorm when running from gulp

I'm fairly new to this, but I really tried my best looking for up for answers.
I used yeoman to generate an application. (used 'angular fullstack' - https://github.com/angular-fullstack/generator-angular-fullstack)
It has a gulpfile.babel.js config file, which runs nodemon.
What I'm trying to do is to make the gulp serve nodemon instance to hit the Webstorm breakpoints I have.
What I've tried so far :
-- Regular debugging. (trivial..) But it seems node sends excpections when he meet ECMA6 syntax. (Still.. I rather run the gulp instance than run it from webstorm.)
-- Using --debug
-- Using 'remote debug' in webstorm.
-- Setting up node inspector in gulp task and set him to listen 5353
-- Using --debug-brk and debug on port 5353 (for example)
I could really appreciate it if someone could help me.
This guy here says Webstorm can't handle this case, but it's weird, you can debug remote servers but you can't debug gulp nodemon server instance?
Debugging node app in WebStorm when run from gulp
Assuming you are using Node.js. It provides node inspector to debug the server side files on the chrome browser itself, with similar experience given in browser debugging.
Here is the reference link to set up the node inspector.
Following are the steps to set node inspector.
1) Install node inspector with command
npm install -g node-inspector
2) Start node inspector
You can start it from any directory
node-inspector
As a result, you will receive a url to debug in browser
3) Restart the node server in debug mode
change the directory to the server folder of your project
cd /path/to/your/project/directory/nodejs/server
node --debug server
4) once the server is started in debug mode successfully, copy the url received in above result and open it in Chrome browser. There you can see all the server side files of Node.js on the source section of the debugger, where you can apply the breakpoints on the server javscript files those have been written.

Protractor local and global installations behaving differently

This is a rough one. Two fellow developers and I have been working for nearly 24 hours on this. I have a conf.js that I can navigate to in Terminal and then run protractor conf.js (using the globally installed copy) and it runs perfectly. One at a time, each green dot appears after each successful test, and it takes about 80 seconds. Here's where it gets tricky.
If I force the local installation of Protractor to run by executing (path of project)/node_modules/protractor/bin/protractor conf.js then it fires up, shows me several green dots all at once, then throws an error about not being able to hook into angular. This is causing trouble with integrating with our build, since grunt looks for and uses the local copy of Protractor.
To further complicate matters, one of the two other developers can pull down my repo and run the local protractor installation on my conf.js no problem. It works 100%.
Error while waiting for Protractor to sync with the page: "window.angular is
undefined. This could be either because this is a non-angular page or because your
test involves client-side navigation, which can interfere with Protractor's
bootstrapping. See http://git.io/v4gXM for details"
We've checked all of the following:
Both local and global installations of Protractor are the same version, installed with npm.
Richards-MacBook-Pro:protractor richardpressler$ npm ls protractor
wear-test-web-framework#0.0.1
/path_to_project/wear-test-track0
└── protractor#3.1.1
Richards-MacBook-Pro:protractor richardpressler$ npm ls -g protractor
/usr/local/lib
└── protractor#3.1.1
Selenium is up-to date. We have run both (path to project)/node_modules/protractor/bin/webdriver-manager update as well as webdriver-manager update to update both local and global selenium server installations
I've tried firing up Selenium separately and then pointing Protractor to it so that I can see the output and it looks great when I run the conf.js using the global protractor (protractor conf.js), showing several [Executing] statements each followed by a [Done] statement. However, when I run the local protractor binary with (path to project)/node_modules/protractor/bin/protractor conf.js, I see that Protractor was able to connect to the Selenium instance, but didn't do much afterword:
When the protractor output looks like this:
Richards-MacBook-Pro:protractor richardpressler$ ../../node_modules/protractor/bin/protractor conf.js
Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
.......................
The Selenium server only outputs this:
10:35:47.612 INFO - Selenium Server is up and running
10:35:49.479 INFO - Executing: [new session: Capabilities [{count=1, browserName=chrome}]])
10:35:49.487 INFO - Creating a new session for Capabilities [{count=1, browserName=chrome}]
Starting ChromeDriver 2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4) on port 34848
Only local connections are allowed.
10:35:50.516 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome}]]
10:35:50.532 INFO - Executing: [set script timeout: 11000])
10:35:50.537 INFO - Done: [set script timeout: 11000]
Has anyone had similar misbehavior by Protractor when comparing the global, command-line version and the locally installed version in the project?
Thanks
Turns out all of the dependencies for protractor, grunt, selenium, etc. were in devDependencies so when I initially ran npm install it simply didn't install all of the sub-dependencies for those packages. If I move them into dependencies in the package.json, then re-run npm install, it works like a charm. Alternatively, running npm install --dev with those dependencies in devDependencies works fine too.
More info on the differences between dependencies, devDependencies, and peerDependencies can be found here: What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

Grunt grunt-contrib-jasmine

I have recently started to use grunt for JS project.
I have got a plugin called 'grunt-contrib-jasmine' that I'm using for Jasmine testing. I works great but I'm not able to run tests by specrunner in browser. Can I achieve this by using this plugin or do I need to install something else.
Also when a plugin is not required anymore, is it best to just comment it out or is there any command to uninstall, eg: npm uninstall grunt-contrib-jasmine --save-dev
Just for clarification, you can load the _SpecRunner.html file manually in the browser, but the grunt plugin will only run the tests in PhantomJS.
You can specify the keepRunner:true option in your gruntfile to keep the _SpecRunner.html file around after the tests run.
Then you can start a static web server (grunt-contrib-connect, and node-static both work fine for me) to the root of your project, and you should be able to manually open that _SpecRunner.html in a browser and run your tests there.
EDIT: I ended up giving Testem a try, which can launch your tests in PhantomJS and real browsers. It's still early, but I think I'll be setting aside grunt-contrib-jasmine in favor of Testem and grunt-contrib-testem.
grunt-contrib-jasmine is only for headless browser (phantomjs) so I afraid you will not be able to run this in browser. You will need to set up that manually.
In order to uninstall a plugin, use the command you mentioned:
It will remove the entry from package.json and it'll also uninstall the package too.

Categories

Resources