Page Automation (All-Star)

Github

While working for a previous employer, I needed a way to complete a ton of 'In-Home Training' (around 4000 test questions) to get HR off my back about it.

To accomplish this goal, and achieve the venerable title "In-Home Training All-Star", I used the following tools to automate the process.

  • Node.JS
  • MongoDB
  • Mongoose
  • Puppeteer

***Disclaimer***

This whole project took place over the course of about 2 days and 1 all-nighter.

Because I no longer work for this company, and because of the nature of the In-Home Training application, I can no longer access the environment used to develop this codebase.

Basically, when you finish all of the training, you're locked out of the application. In my haste to finish them all, I never got a chance to re-factor, or DRY the code. This leads to one big file of heavily commented, yet filthy code.

To view this monstrosity, go to the index.js file at: https://www.github.com/cheston/All-Star

The Basic Run Down.

In-Home Training is an online test-taking application for employees to read source material about the various departments of the company, and then take a multiple choice test about the knowledge you just learned. This is to be completed on your own time, and thus nobody really cares about it except HR, who pushes it relentlessly.

There are 28 courses, each course has between 6-12 tests, and each test has between 10-30 questions. The total number of questions is unknown even to me for reasons you will learn later.

You may be wondering 'Why would anyone do all this work for free?". And that is exactly what the vast majority of employees say. However, you're not totally unrewarded. For each course you complete, you receive a fancy shirt, and if you complete all of the courses, you get a winter jacket!

So now that we have our motive, lets break things down.

The basic process is...

  1. Navigate to the application
  2. Enter Login details
  3. Navigate to the tests
  4. Do test

Sounds pretty straight forward right? Well its not, because who ever developed this application decided to give everything very inconsistent class names, so you'll have to do all this with a combination of class names, and :nth-child selectors to get to the correct elements. This is a constant pain throughout the entire process.

So now you've logged in, and you're looking at a test. What do you do? Purposfully fail the test! See, when you fail the test, it tells you all the answers to the questions you got wrong. The only down side is, you're locked out of the test for 15 minutes.

From here the basic algorithm looks like this.

  1. Loop through all the questions on test
  2. If question is in the database, select the database answer
  3. Else, select answer A. and store that answer in the database as the correct answer

So we go through all the questions, and because we dont actually know the answers yet, we fail the test.

Now we're at the failure screen and son-of-a-gun, all the answers are here! Now all we have to do is update all our questions with the correct answer.

Our data schema looks like this

{
  title: String,
  question: String,
  answer: String,
}

All we really care about are the question and answer fields, the title is really just for troubleshooting.

From here, our algorithm is looking like this.

  1. Loop through all the answers
  2. Look up question in database
  3. Update the answer to that question with the correct answer

Far Out! We can just run the same code again and get everything correct! This means we're dont right?

Wrong.

See, each test randomly picks from a pool of possible questions. And let me tell you, there can be a whole hell of a lot for one test! For this reason, its difficult to know exactly how many questions there actually are in total, however I can tell you It took me 3753 questions to pass all the tests.

So naturally, we just run the same exact algorithms over each test until we successfully answer at least 80% of the questions correctly.

In Closing...

This was a challenging project, filled bugs, new technology, errors, and filthy-dirty code, but it was absolutely the most fun project Iv ever worked on.

Fun Fact 1:

On exactly one occasion, answering A. to all the questions was enough to pass a test.

Fun Fact 2:

I had to do a test in the Spanish course by hand because the test question did not exactly match the test answers.

Fun Fact 3:

I have 27 shirts(and the jacket) in the trunk of my car because I have no other place for them.