$FIXTURESdirectory on the Virtual Server.
$STUDENTdirectory in case the student solution needs some input files to run correctly.
setup.shscrip and upload it as a fixture to CodeGrade and The full script would be (from Johan Holmberg’s GitHub):
helpshould open the CodeGrade Help Center (help.codegrade.com) in a new pop-up window.
index.htmlfile, next to that they may upload
baseURLconstant points to the $STUDENT directory where our students submission files can be found.
fileUnderTestis the name of the student's html file to be tested. Change this accordingly.
getElementByTagare functions that will help us navigate in the browser.
getElementByIdto find an element with the ID
click()action on the button
Email sent!, to the actual title and capture the result.
'help.codegrade.com'. The test suite is written as follows:
getElementByIdfunction to look for a button with the ID
click()function to simulate a click on the button.
WindowHandlessince the pop-up is considered a new window.
WindowHandlesto have a length of 2.
help.codegrade.comin the URL. If so, the test passes.
selenium.test.js, which we will upload as a fixture to CodeGrade. In this instance, we nested the two tests in a test suite,
describe('Testing the functionality of your buttons'), which appears as a label in the CodeGrade UI (see screenshot later in this blog).
$FIXTURESfolder) and have run
setup.shin the Global Setup Script to install and configure the virtual environment, it is now time to configure student environment for our Jest and Selenium testing.
jest.config.js. This mandatory configuration file can be left empty if wished for. Our simple configuration file is found below and can be tweaked with the help of Jest’s configuration documentation here. We upload this
jest.config.jsfile as a fixture.
setup_student.sh, which moves our configuration file to the current student directory and moves our tests to a new directory called
$FIXTURES/setup_student.shin the Per-student setup script.
customfrom the drop-down menu of unit testing frameworks. Because we need to run Firefox ‘headless’ (i.e. without a graphical display), we need to run our tests using the
xvbftool that we installed earlier. In total, our Program to run will become:
xvfb-run cg-jest run tests/selenium.test.js(or
xvfb-run cg-jest run tests/if we want to run all tests in the
describe()statements are stacked to fill the different labels)
$FIXTUREand automatically run unit tests on the code. We have several built-in options, follow one of the automatic grading guides above to find out more!
$FIXTURE, execute it in this test and make sure it outputs a float between 0.0 and 1.0, this score will then be the number of points a student receives.