BROWSER SYNC headless environment ERROR - angularjs

So i just started learning Angular 2 and after running the npm install command on git bash and opening my text editor, I was trying to run the npm start command to start the typescript and lite server. Everything went well until this error showed up [1] [BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false) and the browser didn't open. Here's how it looks
`
$ npm start
[1] [BS] Access URLs:
[1] --------------------------------------
[1] Local: http://localhost:3002
[1] External: http://172.30.31.239:3002
[1] --------------------------------------
[1] UI: http://localhost:3003
[1] UI External: http://172.30.31.239:3003
[1] --------------------------------------
[1] [BS] Serving files from: ./
[1] [BS] Watching files...
[1] [BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)
`
I'm using a Windows 8 64bit OS and Chrome is the default browser
A related question https://stackoverflow.com/a/42845813/8130472 was answered and suggested the option of adding C:\Windows\System32 to the System Variables but i don't know how to go about it.
Also, on this link, https://forums.bignerdranch.com/t/browser-sync-couldnt-open-browser/10936/4 another suggestion was to add the --browser"chrome.exe"(Windows). That didn't work either.
Any suggestions? Or Solutions?

So while I kept browsing, i found a clue to the solution of this problem on this webpage https://gist.github.com/Kenty/9096000/revisions which hinted me of where i could find the open option from the error message. I decided to searched for "bs.config.js" on my pc and i found a file called default.config.js in my \Template\node_modules\browser-sync\lib folder under my angular folder and when i searched through the file, i finally found the open option and changed the open option from "local" (which is the default option) to false (Note, it's without the quotes) and when i ran the npm start command again, on the git-bash terminal It worked and there were no more errors.

Add browser attribute, for instance to use firefox : firefox: '-browser "firefox.exe"'
browserSync.init({
server: "./src",
firefox: '-browser "firefox.exe"'
}

A related question https://stackoverflow.com/a/42845813/8130472 was answered and suggested the option of adding C:\Windows\System32 to the System Variables but i don't know how to go about it
About adding to system variables, you can go to "This Pc" properties then to left side bar "advanced system settings" then at bottom you will see "environment variables". You will see Path variable listed double click and copy paste above path i.e C:\Windows\System32
After restart this really solved my browsersync problem.

I tried this command and it worked for me:> browser-sync start --server --browser "chrome.exe" --directory --files "*"

you have to change something in Packages.congig file in visual studio
{
"port": 3000,
"server": {
"baseDir": "."
},
"browser": ["chrome"]
}
It worked in my computer, you should try it at once

Just running cmd as admin might solve the problem

I also had the same problem.
Open your favourite browser and in the search bar explicitly write the local access URL just mentioned above the error you got in the command promt like localhost:3002. You might have got port number like 3000 or 3001 there. Press enter and Browsersync would be connected and index.html is executed.
I hope this works for you as well!

Related

browser does not launch on running react project on wsl (zsh)

I am working on a simple react project on Windows 10 Pro. On trying to run the project with wsl with zsh (npm start) everything works, I get warnings and compilation is done without any errors. The issue I am facing is automatic launch of browser from wsl is not happening.
If I manually open localhost:3000 on my chrome after this command everything works but I would like the wsl terminal to launch my browser on npm start automatically just like it does in most of my other terminals and powershell on windows.
What I have tried:
added a export browser property to my .zshrc with path to chrome from here
Added a bsconfig file to root with following code to set open = true as per from here
I have added the ports from 3000-3999 to my firewall so that wsl can access my host (localhost ip). this fixed previous issue where localhost:3000 would show connection refused error.
I would be happy to provide any more details.
I am very new to wsl and zsh and I would really appreciate any help. Thanks

How to set the environment variable CHROME_BIN when working in an IDE?

I'm trying to follow the AngularJS tutorial: https://docs.angularjs.org/tutorial. I use the IDE Cloud9.
When I enter npm test it returns No binary for Chrome browser on your platform. Please, set "CHROME_BIN" env variable. And the same message for FIREFOX_BIN.
How am I supposed to set these environment variables?
I've tried the following:
In the command prompt of Windows (on my pc, not in cloud9) I entered SET CHROME_BIN = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" but this didn't make a difference.
I also tried it when changing karma.conf.js to:
browsers : ['C:/Program Files (x86)/Google/Chrome/Application/chrome.exe', 'C:/Program Files (x86)/Mozilla Firefox/firefox.exe'],
but then I got the error Can not load "Script", it is not registered! Perhaps you are missing some plugin? so that doesn't seem to be the right way to go either.
If in Cloud9 I enter env SET CHROME_BIN = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" it returns env: SET: No such file or directory.
I also ran into the same problem using the Cloud9 IDE.
While, I didn't solve the Chrome problem, I went with PhantomJS, which worked with Cloud9.
To install on the command line:
npm install karma-phantomjs-launcher --save-dev
In the karma.conf.js file:
// start these browsers
browsers: ['PhantomJS'],
Add variable for the current user using powershell:
[Environment]::SetEnvironmentVariable("CHROME_BIN",'...', "User")
This is not exactly the same as what you want as variable will not be temporary but the effect will be the same.
Your own command will work if you execute it in the same shell as npm:
PS> $Env:CHROME_BIN = '...'
PS> npm test
...
I am using here Powershell syntax exclusively.
I am not familiar with Cloud9 but generally, to set variable up for the IDE you would need to run it from the script that sets the variable prior to launching the IDE (the same as I showed you with nmp above).

Fatal error: spawn cmd ENOENT - Grunt Serve

When i run grunt serve i get this.
Running "browserSync:livereload" (browserSync) task
[BS] Access URLs:
------------------------------------
Local: http://localhost:9000
External: http://192.168.1.5:9000
------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.5:3001
------------------------------------
[BS] Serving files from: .tmp
[BS] Serving files from: app
[BS] Watching files...
Fatal error: spawn cmd ENOENT
Hello Stackoverflow! I have been trying get the yeoman-angular server running. I have got the server running before but now i keep getting this error.
I believe the major problem here is Spawn cmd ENOENT. I have googled the error but i still have no idea what to do. It seems my Path environment is messed up. Please help!
I had this same error running grunt serve on a 64-bit Windows 7 system. I've never experienced this problem on my Macbook Air. What worked for me was right-clicking and opening the Command Prompt using "Run as Administrator." I was then able to navigate to my project directory and run grunt serve without errors. I noticed that this modified my system path, so I agree that this is probably a path-related issue.
I had the same problem running browserSync on Windows 7 64-bit.
Just in case if anyone stumbles across the same problem, I had to add %SystemRoot%\system32 to PATH environment variable and it solved the issue. %SystemRoot% usually resolves to C:\Windows\system32 (and it contains cmd.exe).
I remembered this solution from one of the issues in GitHub browser-sync repo. I will update the answer with the issue link, if I find it.

Setting up Protractor to automatically open and close Selenium

I'm trying to set up E2E testing on one of my windows asp.net (mvc->angular)projects.
We use team city to do our builds so I want my configuration to work on my box and on the build box.
I'm stuck trying to set up the values in conf.js so that protractor will automatically start up and stop when protractor needs it...
I run it via a batch file like this:
call npm install -g
call C:\Users\brown.ericw\AppData\Roaming\npm\protractor conf.js
pause
Everything was working fine when I was running selenium manually.
But I just can't figure out the right conf.js to get selenium started and shut down automatically(Stopping it in the bat file was not always effective, despite several different approaches).
I've tried lots of different combos, but I'm stumped.
Here is the relevant portion of my conf.js:
exports.config = {
seleniumjar: '.\node_modules\protractor\selenium\selenium-server-standalone-2.45.0.jar',
//seleniumArgs: '-Dwebdriver.chrome.driver="\node_modules\protractor\selenium\chromedriver',
//chromeDriver: '.\node_modules\protractor\selenium\chromedriver',
//chromeDriver: '.\node_modules\protractor\bin\webdriver-manager',
chromeDriver: 'C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver',
//seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'e2eTests/*.js'
],
I have protractor installed under my project folder, so I run npm install, so I know it's all kosher at the beginning of the run on the build/test server.
Here is the error I'm getting.. Clearly I can't I figure out the setting to get get it pointing towards the chrome driver...
D:\TFS\TACAdmin3G_Test_E2E>call
C:\Users\brown.ericw\AppData\Roaming\npm\protra ctor conf.js
[launcher] Process exited with error code 1
C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_modules\q\
q.js:126
throw e;
^ Error: Could not find chromedriver at D:\TFS\TACAdmin3G\node_modules\protractor\ selenium\chromedriver
at LocalDriverProvider.addDefaultBinaryLocs_ (C:\Users\Brown.ericw\AppData\R
oaming\npm\node_modules\protractor\lib\driverProviders\local.js:54:15)
at LocalDriverProvider.setupEnv (C:\Users\Brown.ericw\AppData\Roaming\npm\no
de_modules\protractor\lib\driverProviders\local.js:71:8)
at Runner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac
tor\lib\runner.js:265:31)
at TaskRunner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\pro
tractor\lib\taskRunner.js:123:19)
at createNextTaskRunner (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modul
es\protractor\lib\launcher.js:220:20)
at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\lib\laun
cher.js:243:7
at _fulfilled (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Brown.ericw\AppData\Roaming\npm\node_
modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\Brown.ericw\AppData\Roaming\npm
\node_modules\protractor\node_modules\q\q.js:759:13)
at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_mod
ules\q\q.js:573:44
I tried changing the slashes because of the space in the path up there and it changed back to the normal path:
Error: Could not find chromedriver at D:\TFS\TACAdmin3G\_Test_E2E\..
which doesn't give me the whole path.
chromedriver.exe is in all the locations in the various commented version in the conf.js. but no joy truing each of them.
I need to use relative pathing because the root folder on my box is different than the one on the build server.
Any help is greatly appreciated.
Forgot to say I looked at this one:Protractor does not find chromedriver: The driver executable does not exist:
and this one
how to close selenium webdriver at end of test?
and wasn't able to figure it out
Okay every body, for those who follow ,here is the answer to the problem and why I think this is what works. This answer works in my node.js project in VS(have to add the packages here too) , in a batch file on my dev box, and in team city.
I added NPM INSTALL to my build script, so that once the code is pulled down it immediately puts all the js packages in the code directories.
Then I added the selenium server stand lone package to my project(and package.json so I knew exactly where the jar is. I added it as a --Save(write to config)and as a --Dev (add in the dev section, ie include in node_models in my code folders)
Then I have this in my conf.js
> exports.config = {
> seleniumServerJar: 'node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.45.0.jar',
> chromeDriver: './node_modules/protractor/selenium/chromedriver',
> //seleniumAddress: 'http://localhost:4444/wd/hub',
There are several subtle but important changes.
1
seleniumServerJar vs seleniumjar - there are a lot of examples out there using seleniumjar... so I'm guessing the standard tag changed at some point, but seleniumServerJar is what is shown on the documentation pages and it's what works.
2
/ vs \ as the slash in paths.. this one was tricks because when I used backslash, it didn't complain, the only difference was it truncated the path with a ... in the error messages, but when i dug in deeper, backslashes are getting removed from the part of the path you enter... even the part the code uses based on .\ has back slashes... so only use forward slashes in paths in these tags in conf.js
3
Relative pathing with ../node_modules vs .\node_modules vs node_modules..., there are examples out there with all of these used, once I was able to see the full paths being generated I figured out that ../ wasn't what I wanted.. so I played with it and got it working with one ./ and one nothing... why they both didn't work with ./ I don't know.. but it works.(sorry about that)
Just in case it helps you here is my package.json
{
"name": "_Test_e2e",
"version": "0.0.0",
"description": "_Test_e2e",
"main": "app.js",
"author": {
"name": "Brown.EricW",
"email": ""
},
"devDependencies": {
"jasmine-reporters": "^1.0.0",
"protractor": ">=0.14.0-0 <1.0.0",
"selenium-server-standalone-jar": "^2.45.0"
},
"scripts": {
"postinstall": "webdriver-manager update"
},
"dependencies": {
"jasmine": "^2.3.1",
"jasmine-reporters": "^1.0.0",
"protractor": "^2.1.0"
}
}
Running real browsers on build server probably isn't a good solution. If you have a dedicated Teamcity node, then a headless browser implementation like PhantomJS could be an option. You need to make sure that PhantomJS is installed on your dedicated node and its executable is placed somewhere in the PATH. Also make sure to set browser name to be phantomjs instead of chrome.
Secondly you could setup a Selenium grid and setup nodes with different browsers you want to test. From build server you would run tests on the remote selenium grid on the browser of your choice. There are paid, third part options like sauce labs or browser stack if you wish to go that route.
I would tend to go with second option since PhantomJS is not a real browser and you may have requirement of testing your application on different browsers/platforms etc.

Can't connect to localhost:8080 when trying to run Google App Engine program

I'm trying to run the Google App Engine Python 2.7 Hello World program and view it in a browser via Google App Engine Launcher. I followed the install and program instructions to the letter. I copied and pasted the code in the instructions to the helloworld.py file and app.yam1 and verified that they are correct and in the directory listed as the application directory. I hit run on the launcher and it runs with no errors, although I get no sign that is has completed (orange clock symbol next to app name). I get the following from the logs:
Running dev_appserver with the following flags: --skip_sdk_update_check=yes --port=8080 --admin_port=8000 Python command: /opt/local/bin/python2.7
When I try to open in the browser via the GAE Launcher, the 'browse' icon is grayed out and the browser won't open. I tried opening localhost:8080 in Firefox and Chrome as the tutorial suggests, but I get unable to connect errors from both.
How can I view Hello World in a browser? Is there some configuration I need to make on my machine?
I had the same problem. This seemed to fix it:
cd to google_appengine, run
python dev_appserver.py --port=8080 --host=127.0.0.1 /path/to/application
at this point there is a prompt to allow updates on running, I said Yes.
At this point the app was running as it should, also when I quit this and went in using the launcher again, that worked too.
I have to manually start python and make it point to my app folder, for instance in a command line window on Windows I am using python. I installed python in C:\Python27 and my sample app is in c:\GoogleApps\guestbook
C:\Python27>dev_appserver.py c:\GoogleApps\guestbook
and then I can start my app in the Google App Engine Launcher and hit localhost 8080
How about specifying --host argument? You can find it at the bottom of following doc.
https://developers.google.com/appengine/docs/python/tools/devserver
This might be a little late. But still someone might find it useful.
When ever you go and try changing the port number from 8080 to something else, it will not get updated. So the best option is:
Go to your user directory: eg: C:\Username
There will be a Google folder. Go inside
Open the file google_appengine_projects.ini
Change your port number from 8080 to whatever you like 8081
Save it and close the file.
Launch the GAE Launcher again and you will find the changes reflected and the app runs without issues.
7: Access the application using: http://localhost:NewPort/
This can be used to change ports both run port and admin port for your individual projects running locally.
Hope this helps!
The 8080 portion of your url is a port number. Firefox disables visiting url's of other ports by default. You have to enable them by doing the following: http://blog.christoffer.me/post/2012-02-20-how-to-remove-firefoxs-this-address-is-restricted/
Paraphrasing that website:
Open firefox and visit about:conf
In the Filter box, type in network.security.ports.banned.override
If you can't find such a preference, right click to open up the pop-up menu and pick New and then String
As preference name type network.security.ports.banned.override and 8080 as the value.
Done!
It's likely if this continues to not work that your browser is behaving properly (8080 is a fairly standard port). That means that its a problem with the server and we'd have to do some more debugging.

Resources