I'm testing a native ios/android app using a webdriverio boilerplate (https://github.com/webdriverio/appium-boilerplate) project as basis.
But for some scenarios I need to put a user with a precondition info, and for that i want to send a HTTP request to a webserver to set the info for that user.
There is any way to send a post wile using webdriverio an appium on native apps?
I'm trying to send the post after initialize the app but nothing seems to be happening...
You can make HTTP POST request using webdriverio. It doesn't matter what the mode of test(appium, selenium, cucumber, etc.,.)
Please try this answer if this helps:
How to use 3rd party method that takes callback in webdriverio
Related
A novice javascript developer here!
A have a basic question on whats the best and secured way to make HTTP calls from a front application to a backend service that needs an authentication. My application is a SPA (using Vue.js) & getting data from Java services. Java services need authentication details and return sensitive user data.
I see there are a few options and I wanted to understand a better approach amongst all 3-
Making direct HTTP calls from javascript code- Concern for using this approach is, as Javascript code can also be viewed via dev tools in browser, wont it be easier for anyone to do an inspect and view all critical authentication details hence making overall integration less secure?
Making an HTTP call using Axios via Vue framework- Seems like Axios is Promise based HTTP client for the browser that lets you easily make HTTP calls without much code overhead. but is this secure? is Javascript code loaded in the browser? Or the front end code sends the request and axios makes the request from backend server where the application is hosted?
Using Node- If front end application has unique routes configured for each API call and in my application if I have a route mapping to use request module and node js backend code to make those HTTP calls, is that going to be a robust and secure way of integration?
Please let me know your thoughts and apologies if this is a dumb question!
Not dumb at all. You're just learning.
My first question to your answer 😅 will be: is your application server-side rendered or it's sap + backend?
If it's server-side rendered then I would say it's secured since Node will be sending pages with all required data. On the dev tool, you will only see static files being loaded.
However, if it's SAP, I am not sure whether there is a way to hide whatsoever you send to the server from the dev tool. The only one thing you will need to do is to make sure you encrypt whatever is sensitive to your application.
I do integration testing in my Vue SPA with webdriverio and cucumberjs.
When loaded my application does request to get data from api-server.
In my tests I'd like to modify / stub data returned from api-server without 'touching endpoint' (i.e. deny request and return my json).
Nock, moxios and others won't work as my application is loaded with selenium.
I am aware about json-server, wiremock, but I don't want to modify my source code (urls) just for testing purposes.
Ideally selenium / webdriverio should intercept request or add custom code to webpage and return my json.
What options do I have?
Selenium was designed for end-to-end testing and it doesn't provide any mean to mock/stub the requests.
But there're some ways to do so:
Launch the browser on a proxy server which will intercept the requests and mock or redirect them (see browsermob-proxy).
Launch the browser with a web extension to intercept and mock the requests.
You can either code your own web extension or you can use one like Wiremock extension if you are using Chrome/Chromium.
Inject some Javascript in the page to hook XMLHttpRequest.
Since Selenium doesn't provide a way to inject the code before page is loaded, it will only work on the requests triggered upon mouse/keyboard input.
Are there are any good simple examples of sending http requests with data from reactjs/flux to nodejs and from the nodejs server sending back an HTTP response with data? I was able to do this in AngularJS with Nodejs since it had a $http service but am confused on how to do this with reactjs. Any help is appreciated.
ReactJS does not come with a http service like you have in AngularJS. That is the way they keep their Library lean.
For making http requests, you can use:
JQuery (Most advised, as its the most used library on the frontend and probably your project or theme is already using it, so no need to include any new library).
Axios, really nice implementation of the Promise API and Client side support for protecting against XSRF (plus supports IE8)
Fetch, built by Github so support is pretty good
Superagent, small, easy to use and easily extensible via plugins
I am developping a RESTful Node.js API (express+mongoose)
This API calls a third party Oauth API (google, facebook, whatever).
I've been quite happy setting up automated testing with mocha+chai+request so far, but I'm having trouble mocking the third party API to test the route (of my API) that calls it.
I've tried using nock, but it doesn't work for my use case.
To run my tests, I start my API (npm start), and in another tab, I start the test suite (npm test). The test suite uses request to test the API over HTTP.
Hence I think nock doesn't work here because it is mocking http in the 'test suite' process and not in the 'API' process.
I absolutely need to mock this third party call for 2 reasons:
1. I want to be able to run my test suite offline with everything running on my laptop
2. Since the third party API uses Oauth, hard coding credentials in the test suite (even for a test account) doesn't seem too easy.
I would really love not to leave this giant hole in my test coverage, so any advice would be much apreciated!
so this is how I solve my own problem. I came up with it on my own while setting up proper testing for an app for the first time so feel free to suggest improvements. Disclaimer: I use coffee script
The first step was to launch my app from another file, starter.coffee, that essentially looks like this:
# This file starts the API locally
require './test/mocks/google_mock'
require './app'
So to start my server for tests, instead of doing coffee app.coffee, I would do coffee starter.coffee.
The google_mock.coffee file mocks the Google API before the app is launched from the app.coffee file.
For that I use the nock! package.
The google_mock.coffee files looks like this:
nock = require 'nock'
# mocking up google api
googleapis = nock('https://www.googleapis.com')
.get('/userinfo/v2/me')
.reply(401)
with a lot more lines for mocking other Google api calls.
I have recently started learning how to use node.js and Meteor. I am trying to create a small app that I can query via a client built in meteor, but also query that same MongoDB via SMS using the Twilio API. I can see that this can be done with Express: How can I respond to incoming Twilio calls and SMS messages using node.js? but I wanted to use Meteor because of its apparent ease-of-use and integration with a database. I've been reading various questions about routing templates and serving static html pages in Meteor, but is there a solid way someone think I can make this work? Should I just go back to plain Express?
Twilio expects you to give them the URL where the XML response will be hosted: http://www.twilio.com/docs/quickstart/php/sms/hello-monkey
My earlier response is outdated. Today one should use iron:router and create a server-side route.