How to reach appium server from android emulator - javascript

Within a ReactNative android application, I want to detect a running appium service (an end to end server) so my app knows that it is currently running e2e.
From within my android emulator, to reach my localhost, considering Android emulator use localhost for it's own network interface, I have read that android developer use 10.0.2.2 to reach the host localhost.
This is what I have tried:
// iOS/Android e2e test run on Emulator/Simulator with an Appium server
let isE2e: boolean | null = null
export async function getIsE2e() {
if (env.ENV === 'production') {
isE2e = false
}
if (isE2e === true || isE2e === false) {
return isE2e
}
try {
const response = await fetch('http://10.0.2.2/status', {
mode: 'cors',
headers: new Headers({
accept: 'application/json',
}),
})
isE2e = response.ok
} catch (error) {
isE2e = false
}
return isE2e
}
I have the following error:
TypeError: Network request failed
I expect to have the following JSON result:
{"value":{"build":{"version":"2.0.0-beta.46","git-sha":"258938ef66a2a49a4a400554a6dce890226ae34c","built":"2020-03-05 23:13:56 -0800"}}}
I do not use any proxy, this is the configuration:
The appium server listen on 0.0.0.0:4723:
tcp 0 0 0.0.0.0:4723 0.0.0.0:* LISTEN 26721/node
It work fine if I want to reach another service such as a running webpack dev server running on 0.0.0.0:3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 30217/node
Why can't I contact the appium service ?

It is necessary to allow clear text traffic for 10.0.2.2,
Create an xml directory in : android/app/src/main/res/
mkdir -p android/app/src/main/res/xml
Create a file in it network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
</network-security-config>
Edit AndroidManifest.xml by adding android:networkSecurityConfig="#xml/network_security_config" in application.
Source : https://medium.com/livefront/how-to-connect-your-android-emulator-to-a-local-web-service-47c380bff350

Related

Browser-sync - proxy a domain gets HTTP error 403 - you don't have authorization to view this page

I run a gulp task using NodeJS module browser-sync as below.
=== File gulpfile.js ===
let browserSync = require('browser-sync').create();
gulp.task('browser-sync', function(){
browserSync.init( {
open: true,
injectChanges: true,
proxy: 'https://generalgulp.devsunset',
host: '192.168.1.76',
serveStatic: ['.'],
https: {
key: 'C:\\WebProjects\\GeneralGulp\\resources\\certificates\\server-generalgulp.key',
cert: 'C:\\WebProjects\\GeneralGulp\\resources\\certificates\\server-generalgulp.crt'
}
});
});
=== ===
My local project information is as below (I use latest up to current post date):
Node version: 17.1.0
NPM versions: 8.1.3
gulp: 4.0.2
NPM module browser-sync: 2.27.7
I run the browser-sync task. The output looks good.
==>
Using gulpfile C:\WebProjects\GeneralGulp\gulpfile.js
[Browsersync] Starting 'browser-sync'...
[Browsersync] Proxying: https://generalgulp.devsunset
Access URLs:
Local: https://localhost:3000
External: https://192.168.1.76:3000
UI: http://localhost:3001
UI External: http://localhost:3001
==>
I already add the SSL certificate for this domain to trusted root. I also have DNS records pointing from this domain ( https://generalgulp.devsunset ) - IP addresses ( 127.0.0.1 & 192.168.1.76)
I can access the site from both local & external address.
However, when I try to access the local resources using proxied domain ( https://generalgulp.devsunset
) , it gets an HTTP 403 :
Access to <my_custom_domain> was denied. You are not authorize to
view this page
I suppose when running my gulp "browser-sync" task, it will translate the custom domain to the https://localhost:3000 or https://192.168.1.76:3000
I have followed exactly the documents of https://browsersync.io/docs . I have also made an attempt with all solutions I could find. Those solutions led me to the gulp task that I wrote at the beginning.
I would appreciate if you can suggest me which things I should do further to troubleshoot why does my browser-sync cannot “proxy” my domain? Is there any parameter missing in my Gulp task?
Thanks !
I have modified the "proxy" parameter as below and it works when i access the proxied domain with given port:
(for my case is http(s)://generalgulp.devsunset:3000 )
`gulp.task('browser-sync', function(){
browserSync.init( {
open: true,
injectChanges: true,
proxy: 'generalgulp.devsunset',
host: '192.168.1.76',
serveStatic: ['.'],
https: {
key: 'C:\\WebProjects\\GeneralGulp\\resources\\certificates\\server-generalgulp.key',
cert: 'C:\\WebProjects\\GeneralGulp\\resources\\certificates\\server-generalgulp.crt'
}
});
});
`
This is a temporary acceptable solution regarding to the current question scope.
However, What i expect is the browser-sync will auto-forward traffic from custom domain ( http(s)://generalgulp.devsunset ) to : ( http://192.168.1.76:3000 ).
Does browser-sync allow users to do it ?

SignalR occurs error [Invalid frame header] when use webpack dev server proxy

SignalR occurs error [Invalid frame header] when use webpack dev server proxy
Win10 + NodeJs(10.15.3)
There is a web frontend project use #aspnet/signalr module, and develop with webpack-dev-server.
I use #aspnet/signalr like this:
const connection = new signalR.HubConnectionBuilder()
.withUrl('/hubs/global', {
accessTokenFactory: () => getToken()
})
.build()
connnection.on('some event', function doSomeThing() {})
connection
.start()
.then(() => console.log('start success'))
.catch(err => console.error(err))
I want proxy the websocket connection to my server, so I have configured my webpack.config.js like this:
proxy: {
'/api': {
target: `http://${devServerIp}`,
changeOrigin: true,
},
'/hubs': {
target: `http://${devServerIp}`,
changeOrigin: true,
ws: true,
},
},
But I got the follow error:
Invalid frame header
I want the dev-server can proxy the websocket request correctly.
Do you have some similar experience to solve this problem?
You should probable change HTTP to HTTPS.

Error: 12 UNIMPLEMENTED: unknown service discovery.Discovery Using Hyperledger Fabric Node sdk Service Discovery

I am trying to use the service discovery by bootstrapping (providing anchor peer) following this documentation: https://fabric-sdk-node.github.io/tutorial-discovery.html. Below is where the error is.
controller.js Error: 12 UNIMPLEMENTED: unknown service discovery.Discovery (I have tried different permutations of the channel.initialize method).
let fabric_client = new Fabric_Client();
let channel = fabric_client.newChannel('mychannel');
let peer = fabric_client.newPeer('grpc://localhost:7051');
channel.addPeer(peer);
try {
let discovery_response = await channel.initialize({
discover: true,
target: peer,
asLocalhost: true
});
} catch (error) {
console.log('discovery response: ', error || discovery_response);
}
I have also added the gossip protocol to the peer docker environment. Also I already able to submit transactions and use the node sdk with no issues except for the service discovery.
The solution was to upgrade the network peers to version 1.2
https://hyperledger-fabric.readthedocs.io/en/latest/upgrading_your_network_tutorial.html

How to connect a node server without browser

I am using node-jet library as message broker using a websocket.
In my code, there is a deamon and there are peers connect to it. In libary documentation its says peers can connect either by websocket or trivial tcp connection (never used second one before)
Here is server code I try to connect (its running when I try to connect)
https://github.com/lipp/node-jet/blob/master/examples/todo/todo-server.js
Everything works fine if I run my peer javascript inside a browser however, I am not able to run it from console.
var peer3 = new jet.Peer({
url: 'wss://217.78.109.178:8090'
//url: (window.location.protocol === 'http:' ? 'ws://' : 'wss://') +
window.location.host
})
documentation says it will use trivial tcp if no url provided so I also tried this. Again works in browser but not standalone. Any idea ? how can I solve this problem ?
var peer3 = new jet.Peer({
})
$ node Peer.js
Peer: connect failed { no remote stack
name: 'jet.ConnectionClosed',
message: '',
url: 'https://github.com/lipp/node-
jet/blob/master/doc/peer.markdown#jetconnectionclosed'
}

Karma/Jasmine Tests and dropbox authentication in javascript

I'm attempting to create some tests using Karma and Jasmine for a javascript application that uses the Dropbox Datastore api.
Here is a simplified test using the introductory Dropbox code from https://www.dropbox.com/developers/datastore/tutorial/js
I've manually authorized the application with Dropbox in the browser before running the test, but when I run the test, it says the client is not authenticated and no error occurs. Is there something extra that needs to be done for it to authenticate when running the tests?
'use strict';
describe('dropbox', function () {
var client = null;
beforeEach(function() {
client = new Dropbox.Client({key: '46tjf8x15q98xic'});
// Try to finish OAuth authorization.
client.authenticate({interactive: false}, function (error) {
if (error) {
alert('Authentication error: ' + error);
}
});
});
it('client is not null', function() {
expect( client ).not.toBeNull();
});
it('authenticated is true', function() {
expect( client.isAuthenticated() ).toEqual( true );
});
});
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.9 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 33.0.1750 (Mac OS X 10.9.2)]: Connected on socket BKoS8rqqeeL7fg3cHEQl
Chrome 33.0.1750 (Mac OS X 10.9.2) dropbox authenticated is true FAILED
Expected false to equal true.
Error: Expected false to equal true.
at null.<anonymous> (/Users/davidsmith/Sites/myapp/test/spec/dropbox.js:23:38)
Chrome 33.0.1750 (Mac OS X 10.9.2): Executed 2 of 2 (1 FAILED) (0.301 secs / 0.009 secs)
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
So, to be able to run the tests, I looked at the local storage for my browser and copied my app's dropbox key/value pair.
In my test script, I added that key/value pair with
var value = '{"key":"46tjf8x15q98xic","token":"srMz5w4ReBsAAAAAAAAAAWfQfibrbJfeI7LVKsbMvxRfX1pdpS6SOKqvN6DcgK1B","uid":"1407454"}';
localStorage.setItem('dropbox-auth:default:cHKvNCKVzU7Jmnyaj1InU8TBCOc', value );
Another related problem (not shown above) is that openDefaultDatastore is asyncronous so in my test script I added some code to wait until openDefaultDatastore finishes before running my tests.

Categories

Resources