Karma/Jasmine Tests and dropbox authentication in javascript - 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.

Related

How to catch user even (click on a button) from windows UWP app while running WinAppDriver (Appium)

I need to catch user even and perform some script after it while driver is running
What I want to solve:
Run auto test on UWP app via WinAppDriver
Perform some steps
Wait for user input
If button clicked -> do script, else user continue using app
import { driver, By2, windowsAppDriverCapabilities } from 'selenium-appium'
const capabilites = windowsAppDriverCapabilities(<WinAppId>);
driver.startWithCapabilities(capabilites, 'http://localhost:4723/wd/hub');
...
let someButton = driver.findElement(By2.nativeXpath("//*/ButtonPosition"))
while (true){
someButton.addEventListener('click', function() {
<somelogic>
})
TypeError: test.addEventListener is not a function
● Test suite failed to run
WebDriverError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: read ECONNRESET

Node JS VPN connect to endpoint

I hope you can help!
I have setup and Amazon echo applcation, the application makes a request to and AWS EC2 instance and gets JSON data as a response, this is working as expected however the use case for the final application is to connect to a private IP sending paramaters to an API to return the same JSON DATA.
for many reasons sadly I cannot share any of the endpoint information.
I need my NODE.js Application to make a request to the private IP over a VPN connection, Im currently using OPENVPN to make local requests to the endpoint.
I have looked at node packages to see if this is possible but I cannot seem to find one, except for this package here
https://www.npmjs.com/package/node-openvpn
This package is has a dependancy thats fails to download, so i got the node_module manually but Im getting an error when i try to execute the code
var openvpnmanager = require('node-openvpn');
var opts = {
host: 'xx.xx.xx.xx', // normally '127.0.0.1', will default to if undefined
port: 443, //port openvpn management console
timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
var auth = {
user: '*******',
pass: '*******',
};
var openvpn = openvpnmanager.connect(opts)
openvpn.on('connected', function() { //will be emited on successful interfacing with openvpn instance
openvpnmanager.authorize(auth);
});
openvpn.on('console-output', function(output) { //emits console output of openvpn instance as a line
console.log(output)
});
openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
console.log(output)
});
// openvpnmanager.getLog(console.log) //get all console logs up to this point
// and finally when/if you want to
// openvpnmanager.disconnect();
openvpn.on('disconnected', function() { //emits on disconnect
openvpnmanager.destroy() //finally destroy the disconnected manager
});
this just gives me an error
Unhandled rejection TypeError: Cannot read property 'writable' of undefined
at Telnet.exec (C:\Users\user\Desktop\alexa- po\node_modules\node-openvpn\node_modules\telnet-client\lib\telnet- client.js:90:24)
If anybody has any suggetions on how to make this possible I would be very grateful.

Nodeclise , Enide does not execute the cluster code on debug mode

I am using Eclipse Enide to build a nodejs application. I am able to run it all right and the web services are running.But while debugging I choose Debug As > Node Application .
I see no error, the console shows debugger is running on port 5858 and 5859 (its a cluster). But the same web service endpoint gives the error as connection refused.
On debugging I see that the cluster code is never executed and the break is never hit.
const throng = require('throng');
var http_servers = [];
throng({
workers: process.env.WEB_CONCURRENCY || 1,
lifetime: Infinity
},mainServerCode);
function mainServerCode() {
// require('newrelic');
var express = require('express'); // this code is never hit
....
What could be the reason and where to check it.
Thanks

How to turn off strongloop loopback-testing console logging?

I have a very simple test case of API done with usage of loopback-testing module.
lt = require('loopback-testing')
assert = require('assert')
describe '/profile', ->
lt.beforeEach.withApp app
lt.describe.whenCalledRemotely 'GET', '/api/profiles/ping', { data: 'test' }, ->
lt.it.shouldBeAllowed()
it 'should have statusCode 200', ->
assert.equal #res.statusCode, 200
it 'should have pong response', ->
assert.equal #res.body.pong, 'test'
and as result of testing I'm getting printed lines at the system console like this ones:
/profile
GET /api/profiles/ping
GET /api/profiles/ping 200 50.639 ms - 15
✓ should be allowed
GET /api/profiles/ping 200 8.026 ms - 15
✓ should have statusCode 200
GET /api/profiles/ping 200 3.633 ms - 15
✓ should have pong response
Is there a way to turn off writing these lines to system console by loopback-testing module? It's simply trashes my mocha reports overview.
Do you have any logging middleware configured in your application? The extra lines look like HTTP access logs produced by morgan.
You need to disable any HTTP logging middleware in your application when running the tests. The instructions for that depend on how you have configured this middleware, could you please extend your question and describe your app setup?

Set an item from localStorage in a protractor test

describe('The feature', function() {
beforeEach(function () {
browser.executeScript('localStorage.setItem("key","value");');
});
it('should do this', function() {
});
});
but i get this error when the test is run against selenium with chromedriver 2.10 and chrome 37
Executing: [execute script: window.localStorage.setItem("key","value");, []])
15:31:29.747 WARN - Exception thrown
org.openqa.selenium.WebDriverException: <unknown>: Failed to read the 'localStorage'
property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: chrome=37.0.2062.120)
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-26-generic x86_64) (WARNING:
The server did not provide any stacktrace information)
Any idea where the problem cam from ?
According to one of the answers at Remove an item from localStorage in a protractor test, this happens when you try to access localStorage without hitting the browser (say, browser.get) first when you are using the Chrome driver. The solution seems to be to hit the browser first (maybe your root page) to get a page loaded in Chrome so that you can manipulate the localStorage. That at least is what I have been doing for our project. Hope this helps!

Categories

Resources