Get Started with Test Users on Graph API

QA Internship Day 4

Objectives

Today, I’ll need to further come out with test scripts for automating the ShopBack’s login process with FB accounts

Plan

  1. First, create test users with graph API (not manually)
  2. When creating FB test user for an app, the FB test user will be able to login to that app (permission is given by default)
  3. Write the script if 2 is verified a. Automate test user creation while storing essential info (app id, secret, access token, login URL, User ID, email & password) in the scripts. Could this be done automatically with wdio or nodejs? b. Automate test user login on ShopBack. c. Check if user is added in ShopBack’s database d. Automate test user deletion with Graph API, to avoid reaching the 2000 test user limit.

(*) To achieve this, I may need to build a simple form with FB authorization, using MongoDB for storing users, and deploy on heroku site. Then I’ll need to write an automatic test script for this simple site, and substitute my app info like ID, access token, app secret with those of ShopBack. Since a FB app-ID is required for FB login through [FB SDK for JS] (https://developers.facebook.com/docs/javascript/quickstart), I should be able to get these info.

Graph API

This is the official API from Facebook that allows third-party apps to read and write to the Facebook social graph.

Jargons

  • Test users: special Facebook accounts, invisible to real accounts, which can be created within an app for the purpose of manual or automated testing of that app’s Facebook integration. Test user accounts cannot find real FB accounts either. Test users can be created automatically with the Graph API or manually via App Dashboard

  • Graph API edge is used for managing the entire test user pool, so mainly it functions at account level - test user creation, disassiciatin/associating test users with apps

  • Graph API node is used for managing activities for each specific test users like posting, liking, commenting and deleting the account.

Automate test user creation with Graph API

  1. Login to FB for developers page with a real FB account.
  2. Go to MyApps, choose the target app or create a new one.
  3. Get AppID and App Secret ready.
  4. Go to Graph API Explorer, change the application dropdown to the target app. 90% of the time this step is missed, so please remember to choose the correct app before proceeding to the next step.
  5. Get your access token ready as well.
  6. Use the following POST request in your automation script to create a new test user
https://graph.facebook.com/{app-id}/accounts/test-users?installed=true&name={any-valid-name}locale=en_US&permissions=email,user_birthday,publish_actions&access_token={app-access-token}

To just play around on Graph API Explorer, set the request type to POST for any version, then paste the string below in, sustituting in the correct values as well.

{app-id}/accounts/test-users?installed=true&name={any-valid-name}&locale=en_us&permissions=email,user_birthday,publish_actions&access_token={app-access-token}

All the {} brackets shouldn’t be there when the string above is replaced with real values.

Feel free to adjust the POST request according to the syntax of your framework.

References:

The 1st answer to this Stack Overflow question

More about the Graph API request fields

More about Graph API permission list

Automate test user deletion with Graph API

Use DELETE request with test-user-id to delete the user.

Written on May 18, 2017