I'm writing Integration Tests using nightwatch.js in a Node.js application. For a particular test case, I want nightwatch to connect via a proxy. What would be the right way to do this? I can't find anything from its official documentation, or from its Google Group.
The Selenium documentation suggests setting it on the webdriver instance as described here. I'm not sure how to do this via nightwatch.
In the nightwatch.json configuration file, you should be able to set a proxy parameter in the desiredCapabilities:
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions" : {
"args" : [
"disable-extensions",
"start-maximized"
]
},
"proxy": {
"proxyType": "manual",
"httpProxy": "your_proxy:8080"
}
}
},
Check this doc: https://code.google.com/p/selenium/wiki/JsonWireProtocol#Proxy_JSON_Object
I stumbled over this Question on my search for socks5 proxy solution.
When I used the implementation from the JsonWireProtocol documentation using the socksProxy property, I always got the following error:
message: 'unknown error: cannot parse capability: proxy from unknown error:
proxyType is \'manual\' but no manual proxy capabilities were found
Using a socks5 proxy configured via a proxy.pac file - proxyType: 'pac' using proxyAutoconfigUrl was working without any problem. But this wasn't suitable for my use case.
After some fiddling around, I finally found two solutions to that problem:
Using CLI args for chromedriver
desiredCapabilities: {
browserName: 'chrome',
/* … */
chromeOptions: {
args: [
'--proxy-server=socks5://proxy_url:proxy_port'
]
}
}
*edit: looks like this has been removed
2. Using sslProxy property
Since socks proxy is in theory nothing more than a ssl tunnel I thought I could give that property another try. The solution that made it finally working looked like this:
desiredCapabilities: {
browserName: 'chrome',
/* … */
proxy: {
proxyType: 'manual',
sslProxy: 'socks5://proxy_url:proxy_port'
}
}
Hope that answer help anyone looking for help regarding socks5 proxy. :)
But more important would be that chromedriver will implement the JsonWireProtocol properly in the future.
Nightwatch changed how the proxy object in the nightwatch.conf.js file works when they started using proxy-agent instead of http-proxy, unfortunately it seems to not be documented anywhere. But it does still exist you just need to pass in different parameters in the proxy object. The 'protocols' it accepts are listed on the proxy-agent github See below for an example.
firefox: {
desiredCapabilities: {
browserName: 'firefox',
version: 'latest',
},
proxy: {
host:'127.0.0.1',
port:8001,
protocol: 'http',
},
},
Related
I am working on Angular 6 application. I was try to run npm audit fix and npm audit fix --force to fix vulnerabilities. After that My application is not compile and working. So I delete package-lock.json, node modules folder and take old package.json file and install npm again.
Somehow I manage to compile and run the application but where I have api calls I am getting this error in browser
And in the terminal:
First time I am facing this type of issue So I have no idea about how to fix it.
Here is my proxy.config.json file where I found http://localhost:30510 url
{
"/api/v0/dataservice/*" : {
"target" : "http://localhost:30510",
"secure" : false,
"logLevel" : "debug"
}
}
I have try below solutions:
Replace localhost with [::1]
try to add
headers: {
"Connection": "keep-alive"
}
add "changeOrigin": true
but not work any above solution
Any help is appreciated. Thanks in advance.
Please try below proxy configuration:
{
"/api/v0/dataservice/*": {
"target": "http://localhost:5000",
"secure": false,
"changeOrigin": true,
"pathRewrite": {"^/api/v0/dataservice" : "/api/v0/dataservice"}
}
}
Also please check whether the backend server is currently working. This error generally occurs when the backend server is not up.
I have a spring boot back-end api and I am trying to call a service for uploading or getting images from angular project. I have a standard proxy.conf.json file:
{
"/api": {
"target": "localhost:8080",
"secure": false,
"logLevel": "debug"
}
}
if my angular service is using Http(HttpModule) everything is ok, but since its deprecated and i want to do it the new way i am trying with HttpClient(HttpClientModule) but in log i am getting :
[HPM] Error occurred while trying to proxy request /upload/ from localhost:4200 to localhost:8080 (ENOTFOUND) (https://nodejs.org/api/errors.html#errors_common_system_errors)
and it is not working. On one try on a linux machine i got the same mistake but with (EINVAL). Can someone guide me what i am doing wrong ? Sorry if the question is stupid there are a few questions like this one but neither of their solutions does not seem to work in my case.
Try to set http protocol in front of the localhost link.
{
"/api": {
"target": "http://localhost:8080",
"secure": false,
"logLevel": "debug"
}
}
i'm requiring a capabilities.js file with an object to my intern suites so i can specify which environments to use for various tests. here is my default chrome:
chrome: {
browserName: 'chrome',
chromeOptions: {
args: [
// 'start-maximized',
'window-size=1024x768'
]
}
}
from this i'd expect something like environments: [caps.chrome] to open a browser window that is 1024x768. I need to specify window size in a per-environment way. (also, start-maximized isn't working- though i do have several mobile emulators set up and doing well).
I did find this which seems to hint that it won't work on a mac. can anyone confirm?
However, the issue linked in the question has been closed for some time.
Arguments not being applied to Google chromedriver in Selenium with python
I use these configs to control windows size on windows, should work on Mac too.
"chromeOptions": {
"args": [
"--window-size=800,600"
]
"chromeOptions": {
"args": [
"--start-maximized"
]
Is there a way to disable images in Chromedriver with Javascript ( Node.js )? I couldn't find a proper answer to this question anywhere!
I do realise this question is quite old, but still - it is the first Google search result for the node chromedriver disable images query. So I decided to give it a go anyway.
I don't know the exact setup the OP was trying to use, so I'll refer to my own. I'm using nightwatch.js with pre-built Selenium running chromedriver. In my nightwatch.conf.js file I have the following setup for the chromedriver:
module.exports = {
"test_settings": {
"default": {
...
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": ["disable-web-security"],
"prefs": {
"profile.managed_default_content_settings.images": 2
}
}
}
}
}
};
The setup above works with
"chromedriver": "^2.21.2",
"selenium-server": "^2.53.0"
and is running Chrome 51.0.2704.84 stable.
I hope that helps someone, as I lost about 3 hours trying to come up with this solution.
Edit: This has since been solved as an interesting network issue, see my comments and answer below.
Original Post:
My goal: Setup proof-of-concept tests on BrowserStack with Intern.
I went through the intern-tutorial, which all worked beutifully for me on Sauce Labs, and now I just want to learn what it takes to modify that configuration to test on BrowserStack, which keeps failing for me.
The terminal command, as per the tutorial:
./node_modules/.bin/intern-runner config=tests/intern
When running that, I get:
Listening on 0.0.0.0:9000
Starting tunnel...
BrowserStackLocal v2.2
Connecting to BrowserStack using WebSocket protocol...
Connected.
Ready
Error: connect ETIMEDOUT
at errnoException <net.js:904:11>
at Object.afterConnect [as oncomplete] <net.js:895:19>
TOTAL: tested 0 platforms, 0/0 tests failed; fatal error occurred
Environment:
OS: Mac OS X 10.9.4
Node: 0.10.29
NPM: 1.4.21
Intern: 2.0.1
Variables set in ~/.bash_profile as:
export BROWSERSTACK_USERNAME="<my_actual_username>"
export BROWSERSTACK_ACCESS_KEY="<my_actual_access_key>"
Intern configuration set in tests/intern as:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.41.0'
},
environments: [
{ os: "Windows", os_version: "8.1", browser: "chrome", browser_version: "34.0" }
],
maxConcurrency: 3,
tunnel: 'BrowserStackTunnel',
tunnelOptions: {
verbose: true
},
loader: {
packages: [ { name: 'app', location: 'app' } ]
},
suites: [ 'tests/hello' ],
functionalSuites: [ 'tests/functional/index' ],
excludeInstrumentation: /^(?:tests|node_modules)\//
});
As in, this is all that has been changed since the completed tutorial:
Removed all but one environment object (for simplicity), modified it to a format supported by BrowserStack.
Set the 'tunnel' property to the appropriate tunnel class.
Set tunnelOptions: { verbose: true } for debugging.
Things I've tried:
Setting BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY inline on the command line when executing the runner, just in case.
Used the configuration here (which I recognize is out of date): https://stackoverflow.com/questions/23304388/intern-js-and-browserstack
Stupidity checks, computer reboots, etc.
My environment object should be valid, as its based on one coming back from:
https://www.browserstack.com/automate/browsers.json
I feel like there's some basic thing here I'm missing about the configuration.
Can you have a look into the intern config file, which I use to run tests on browserstack. Hope it will help you solve your problem.
I have confirmed via A/B testing on different networks and with the same configuration, that this is due to the fact that Verizon Wireless blocks WebSocket connections, which has been reported elsewhere (see my comments on the original question).
This can be very tricky to diagnose. I hope it helps someone in the future!