🌐
Websites
This guide uses some information provided by Johan Holmberg from Malmö University, who has shared his steps to set up Selenium in CodeGrade in a public GitHub repository. You can find that in the link below.
CodeGrade AutoTest runs on Ubuntu (18.04.2 LTS) machines which you can configure in any way that you want.
In the setup section of your AutoTest, you can upload any files you might need for testing. These files are called Fixtures and will be placed in the
$FIXTURES
directory on the Virtual Server.The file structure of the server is like this:
$FIXTURES/
All of your uploaded fixtures will be here.
$STUDENT/
This is where the submission of student is placed.
Tests are executed from this directory.
After uploading any files you might need, you can run some setup to install any packages you might need.
- Global setup script: this is where you install your additional pip packages you want to be available on the server. The global setup only runs once and is then cached, so the student submission won't be available here yet.
- Per-student setup script: this will run once when running the autograding for a student and will run before all tests. This is a good place to move
$FIXTURES
to the$STUDENT
directory in case the student solution needs some input files to run correctly.

Use any command in the Global Setup Script field to install software or run your setup script
- 1.Create a
setup.sh
scrip and upload it as a fixture to CodeGrade and The full script would be (from Johan Holmberg’s GitHub):#!/bin/sh# Installs Jest as per https://help.codegrade.com/user-reference/autotest-general/unit-testcg-jest install# Updates the Ubuntu repo settingssudo apt update# Installs Firefox and a headless X window managersudo apt install firefox xvfb# Installs the neccessary javascript librariesnpm install -g selenium-webdriver geckodriver# Makes the run script executablechmod +x $FIXTURES/run.sh - 2.Run that in our Global Setup Script with
bash $FIXTURES/setup.sh
.
Now that you have created the setup, it's time to create the actual tests. Do this by pressing the "Add Level" button and then the "Add Category" button.
All tests in AutoTest fill in a specific rubric category that you select. After selecting the category, you can start creating tests that will fill it in. Multiple test types are available in CodeGrade, which can be used together depending on your needs and wishes.
For the purpose of this guide, we have designed a very simple example assignment that uses HTML, CSS and some inline JavaScript. We will use Jest and Selenium to assess two parts of the user interface of this website:
- Clicking on one button with the ID
email
should link to a page that has the title “Email sent!”. - Clicking on another button with the ID
help
should open the CodeGrade Help Center (help.codegrade.com) in a new pop-up window.
The student should upload this
index.html
file, next to that they may upload email.html
and style.css
.
Example webpage submission rendered in CodeGrade
Now we can begin writing our Selenium and Jest tests. For this example we will be using a template provided by Johan Holmberg. His template (find it here) starts with the following base code:
const { Builder, By, until } = require('selenium-webdriver');
require('geckodriver');
// This is the directory where the student's submission ends up.
// It can easily be changed to any URL.
const baseURL = 'file:///home/codegrade/student/';
// Change this to select another file to test.
const fileUnderTest = 'index.html';
const defaultTimeout = 10000;
let driver;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5;