Testcafe hands on 2
Checkout new branch
"api-test"
ENV Vars
- Create a utils folder and inside a file called url.js.
- Create a function where you declare and return a variable mainUrl.
- The mainUrl variable will be assign depending a global var called isQA, if isQA is a truthy then mainUrl will have the value "http://localhost:8999", else "http://localhost:1234"
- Inside the utils folder create a file called users.js.
- Create a function name userData where you declare and return an object with properties user, password.
- The user, password variable will be assign depending a global var called isQA, if isQA is a truthy then user will have the value "user", else "user2", same for password where if truthy "pass" else "pass2"
- In the users.js file create another function called getUserRole
- That function will call userData and creates and return an User Role from testCafe and logins the User.
- export all functions.
-
Import all... and use all
process.env
- Node process runs always with a global called process where you an pass ENV variables in the .env object.
- All passed variables are treated as Strings.
- Prepend a node process run with the env variable assignation.
- Usually we use Caps name for those vars.
$ QA=true node app.jsNpm Scripts
- Easy to run processes that are identified with an name that can be run simply by prepending npm run
- start and test, can run with just prepending npm
- Npm scripts have access to local modules, this allowing us to avoid global modules.
$ npm start
$ npm test
$ npm run test-qaLet's move all to npm scripts
Axios for AJAX calls
- Make XMLHttpRequests from the browser
- Make http requests from node.js
- Supports the Promise API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against XSRF
$ npm install axiosLimitations
- When using testcafe the cookies are stored separately not in the same document. So authenticated requests needs to be done manually
Nock for mocking AJAX calls
- Nock is an HTTP mocking and expectations library for Node.js
- Nock can be used to test modules that perform HTTP requests in isolation.
- For instance, if a module performs HTTP requests to a CouchDB server or makes HTTP requests to the Amazon API, you can test that module in isolation.
$ npm install nockvar nock = require('nock');
var couchdb = nock('http://myapp.iriscouch.com')
.get('/users/1')
.reply(200, {
_id: '123ABC',
_rev: '946B7D1C',
username: 'pgte',
email: 'pedro.teixeira@gmail.com'
});IEVMS
- Use VirtualBox
- Microsoft provides virtual machine disk images to facilitate website testing in multiple versions of IE, regardless of the host operating system. With a single command, you can have IE6, IE7, IE8, IE9, IE10, IE11 and MSEdge running in separate virtual machines.
curl -s https://raw.github.com/xdissent/ievms/master/ievms.sh | env IEVMS_VERSIONS="11" bashUsing testcafe IEVMS provider
https://github.com/kartojal/testcafe-browser-provider-ievms
- This is the ievms browser provider plugin for TestCafe. It launchs your Windows VMs previously installed with IEVMS and proceed to run tests in it. When the tests are finished, the VMs are saved and stopped. It can run multiple Internet Browsers/Edge instances at once.
Testcafe hands on 2
By Cesar Guerrero Rincon
Testcafe hands on 2
- 196