Something went wrong on our end
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
ImsQTI21Test.java 7.29 KiB
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.selenium;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.UUID;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.page.InitialPage;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.olat.ims.qti21.QTI21DeliveryOptions.ShowResultsOnFinish;
import org.olat.selenium.page.LoginPage;
import org.olat.selenium.page.NavigationPage;
import org.olat.selenium.page.course.CourseEditorPageFragment;
import org.olat.selenium.page.course.CoursePageFragment;
import org.olat.selenium.page.qti.QTI21EditorPage;
import org.olat.selenium.page.qti.QTI21Page;
import org.olat.test.ArquillianDeployments;
import org.olat.test.JunitTestHelper;
import org.olat.test.rest.UserRestClient;
import org.olat.user.restapi.UserVO;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
/**
*
* Initial date: 03.05.2016<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@RunWith(Arquillian.class)
public class ImsQTI21Test {
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
private WebDriver browser;
@ArquillianResource
private URL deploymentUrl;
@Page
private NavigationPage navBar;
@Test
@RunAsClient
public void qti21Test(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Simple QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/simple_QTI_21_test.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile);
//create a course
String courseTitle = "Course QTI 2.1 " + UUID.randomUUID();
navBar
.openAuthoringEnvironment()
.createCourse(courseTitle)
.clickToolbarBack();
String testNodeTitle = "QTI21Test-1";
//create a course element of type CP with the CP that we create above
CourseEditorPageFragment courseEditor = CoursePageFragment.getCourse(browser)
.edit();
courseEditor
.createNode("iqtest")
.nodeTitle(testNodeTitle)
.selectTabLearnContent()
.chooseTest(qtiTestTitle);
//publish the course
courseEditor
.publish()
.quickPublish();
//open the course and see the CP
CoursePageFragment course = courseEditor
.clickToolbarBack();
course
.clickTree()
.selectWithTitle(testNodeTitle);
//check that the title of the start page of test is correct
WebElement testH2 = browser.findElement(By.cssSelector("div.o_course_run h2"));
Assert.assertEquals(testNodeTitle, testH2.getText().trim());
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.start()
.answerSingleChoice(1)
.saveAnswer()
.endTest()
.closeTest()
.assertOnAttempts(1);
//TODO continue
}
/**
* Check if the hotspot interaction send a "correct" feedback.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21GraphicInteractionTest(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Simple QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/simple_QTI_21_hotspot.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.answerHotspot("circle")
.saveAnswer()
.assertFeedback("Correct!")
.endTest()
.closeTest();
//TODO check the results
}
/**
* Create a test, import the CSV example, remove the
* first single choice which come if someone create a
* test. Change the delivery settings of the test to
* show the detailled results.<br>
* Run the test and check the results.
*
* @param loginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void importQuestionsCSV(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Excel QTI 2.1 " + UUID.randomUUID();
navBar
.openAuthoringEnvironment()
.createQTI21Test(qtiTestTitle)
.clickToolbarBack();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
QTI21EditorPage qtiEditor = qtiPage
.edit();
// import a single choice, a multiple and 2 gap texts
qtiEditor
.importTable()
.importFile("import_qti21_excel.txt")
.next()
.assertOnNumberOfQuestions(5)
.finish();
//remove the single choice which come from the creation
// of the test
qtiEditor
.selectNode("Single choice")
.deleteNode();
// go to options and show the results
qtiPage
.clickToolbarBack()
.options()
.showResults(Boolean.TRUE, ShowResultsOnFinish.details)
.save();
//go to the test
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerGapText("verbannen", "_RESPONSE_1")
.saveAnswer().nextAnswer()
.answerGapText(",", "_RESPONSE_1")
.answerGapText("", "_RESPONSE_2")
.answerGapText("", "_RESPONSE_3")
.saveAnswer().nextAnswer()
.answerMultipleChoice("Deutschland", "Brasilien", "S\u00FCdafrika")
.saveAnswer().nextAnswer()
.answerSingleChoice("Italien")
.saveAnswer().nextAnswer()
.answerCorrectKPrim("Deutschland", "Uruguay")
.answerIncorrectKPrim("Frankreich", "Spanien")
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnResults()
.assertOnAssessmentTestScore(9)
.assertOnAssessmentTestMaxScore(9);
}
}