Skip to content
Snippets Groups Projects
Commit 2498f641 authored by srosse's avatar srosse
Browse files

no-jira: selenium tests for the interactions which are "runtime" only

parent 47441163
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,9 @@ import org.openqa.selenium.WebDriver; ...@@ -44,7 +44,9 @@ import org.openqa.selenium.WebDriver;
/** /**
* This suite tests the interactions in runtime and only in runtime: * This suite tests the interactions in runtime and only in runtime. The source used
* come from the IMS examples.
*
* <ul> * <ul>
* <li>Hotspot * <li>Hotspot
* <li>Associate * <li>Associate
...@@ -52,6 +54,12 @@ import org.openqa.selenium.WebDriver; ...@@ -52,6 +54,12 @@ import org.openqa.selenium.WebDriver;
* <li>Match * <li>Match
* <li>Graphic Gap Match (with click and drop) * <li>Graphic Gap Match (with click and drop)
* <li>End interaction with inline and modal feedbacks (classic hint) * <li>End interaction with inline and modal feedbacks (classic hint)
* <li>Select point interaction
* <li>Position object interaction
* <li>Order interaction
* <li>Graphic order interaction
* <li>Inline choice
* <li>Slider
* </ul> * </ul>
* *
* Initial date: 26 janv. 2018<br> * Initial date: 26 janv. 2018<br>
...@@ -83,7 +91,7 @@ public class ImsQTI21InteractionsTest extends Deployments { ...@@ -83,7 +91,7 @@ public class ImsQTI21InteractionsTest extends Deployments {
authorLoginPage.loginAs(author.getLogin(), author.getPassword()); authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test //upload a test
String qtiTestTitle = "Simple QTI 2.1 " + UUID.randomUUID(); String qtiTestTitle = "Hotspot QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_hotspot.zip"); URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_hotspot.zip");
File qtiTestFile = new File(qtiTestUrl.toURI()); File qtiTestFile = new File(qtiTestUrl.toURI());
navBar navBar
...@@ -175,7 +183,7 @@ public class ImsQTI21InteractionsTest extends Deployments { ...@@ -175,7 +183,7 @@ public class ImsQTI21InteractionsTest extends Deployments {
authorLoginPage.loginAs(author.getLogin(), author.getPassword()); authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test //upload a test
String qtiTestTitle = "Associate QTI 2.1 " + UUID.randomUUID(); String qtiTestTitle = "Graphic associate QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_graphic_associate_ims.zip"); URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_graphic_associate_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI()); File qtiTestFile = new File(qtiTestUrl.toURI());
navBar navBar
...@@ -315,7 +323,7 @@ public class ImsQTI21InteractionsTest extends Deployments { ...@@ -315,7 +323,7 @@ public class ImsQTI21InteractionsTest extends Deployments {
authorLoginPage.loginAs(author.getLogin(), author.getPassword()); authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test //upload a test
String qtiTestTitle = "Simple QTI 2.1 " + UUID.randomUUID(); String qtiTestTitle = "End QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_end_ims.zip"); URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_end_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI()); File qtiTestFile = new File(qtiTestUrl.toURI());
navBar navBar
...@@ -405,5 +413,275 @@ public class ImsQTI21InteractionsTest extends Deployments { ...@@ -405,5 +413,275 @@ public class ImsQTI21InteractionsTest extends Deployments {
.assertOnAssessmentResults() .assertOnAssessmentResults()
.assertOnAssessmentItemScore("Airport Tags", 3); .assertOnAssessmentItemScore("Airport Tags", 3);
} }
/**
* Check if the select point interaction returns 1 point
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21SelectPointInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Select point QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_select_point_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerSelectPoint(100, 110)
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Where is Edinburgh", 1);
}
/**
* Check if the graphic order interaction returns 1 point
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21GraphicOrderInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Graphic order QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_graphic_order_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerGraphicOrderById("A")
.answerGraphicOrderById("D")
.answerGraphicOrderById("C")
.answerGraphicOrderById("B")
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Flying Home", 1);
}
/**
* Check if the position object interaction returns 3 points
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21PositionObjectInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Position object QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_position_object_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerPositionObject(0, 118, 184)
.answerPositionObject(1, 150, 235)
.answerPositionObject(2, 96, 114)
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Airport Locations", 3);
}
/**
* Check if the position object interaction returns 3 points
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21InlineChoiceInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Inline choice QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_inline_choice_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerInlineChoice("Y")
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Richard III", 1);
}
/**
* Check if the slider interaction returns 1 point
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21SliderInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Slider QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_slider_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerVerticalSlider(16)
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Jedi Knights", 1);
}
/**
* Check if the gap match returns 3 points
* if answered correctly.
*
* @param authorLoginPage
* @throws IOException
* @throws URISyntaxException
*/
@Test
@RunAsClient
public void qti21GapMatchInteraction(@InitialPage LoginPage authorLoginPage)
throws IOException, URISyntaxException {
UserVO author = new UserRestClient(deploymentUrl).createAuthor();
authorLoginPage.loginAs(author.getLogin(), author.getPassword());
//upload a test
String qtiTestTitle = "Gap match QTI 2.1 " + UUID.randomUUID();
URL qtiTestUrl = JunitTestHelper.class.getResource("file_resources/qti21/simple_QTI_21_gap_match_ims.zip");
File qtiTestFile = new File(qtiTestUrl.toURI());
navBar
.openAuthoringEnvironment()
.uploadResource(qtiTestTitle, qtiTestFile)
.clickToolbarRootCrumb();
QTI21Page qtiPage = QTI21Page
.getQTI12Page(browser);
qtiPage
.options()
.showResults(Boolean.TRUE, QTI21AssessmentResultsOptions.allOptions())
.save();
// to the test and spot it
qtiPage
.clickToolbarBack()
.assertOnAssessmentItem()
.answerGapMatch(1, "winter", true)
.answerGapMatch(2, "summer", true)
.saveAnswer()
.endTest()
.closeTest();
//check the results
qtiPage
.assertOnAssessmentResults()
.assertOnAssessmentItemScore("Richard III", 3);
}
} }
...@@ -27,9 +27,11 @@ import org.olat.selenium.page.NavigationPage; ...@@ -27,9 +27,11 @@ import org.olat.selenium.page.NavigationPage;
import org.olat.selenium.page.graphene.OOGraphene; import org.olat.selenium.page.graphene.OOGraphene;
import org.olat.selenium.page.repository.RepositoryAccessPage; import org.olat.selenium.page.repository.RepositoryAccessPage;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
/** /**
* *
...@@ -125,6 +127,20 @@ public class QTI21Page { ...@@ -125,6 +127,20 @@ public class QTI21Page {
return this; return this;
} }
/**
* Select the key of the inline choice interaction.
*
* @param key The key to select
* @return Itself
*/
public QTI21Page answerInlineChoice(String key) {
By inlineBy = By.xpath("//span[@class='inlineChoiceInteraction']/select");
OOGraphene.waitElement(inlineBy, browser);
WebElement inlineEl = browser.findElement(inlineBy);
new Select(inlineEl).selectByValue(key);
return this;
}
public QTI21Page answerHotspot(String shape) { public QTI21Page answerHotspot(String shape) {
OOGraphene.waitElement(By.className("hotspotInteraction"), browser); OOGraphene.waitElement(By.className("hotspotInteraction"), browser);
By areaBy = By.xpath("//div[contains(@class,'hotspotInteraction')]//map/area[@shape='" + shape + "']"); By areaBy = By.xpath("//div[contains(@class,'hotspotInteraction')]//map/area[@shape='" + shape + "']");
...@@ -134,6 +150,20 @@ public class QTI21Page { ...@@ -134,6 +150,20 @@ public class QTI21Page {
return this; return this;
} }
/**
* Select the area with the specified data-qti-id.
* @param id The id save in data-qti-id
* @return Itself
*/
public QTI21Page answerGraphicOrderById(String id) {
OOGraphene.waitElement(By.className("graphicOrderInteraction"), browser);
By areaBy = By.xpath("//div[contains(@class,'graphicOrderInteraction')]//map/area[@data-qti-id='" + id + "']");
List<WebElement> elements = browser.findElements(areaBy);
Assert.assertEquals("Hotspot with data-qti-id " + id, 1, elements.size());
elements.get(0).click();
return this;
}
public QTI21Page answerHottext(int index) { public QTI21Page answerHottext(int index) {
OOGraphene.waitElement(By.className("hottextInteraction"), browser); OOGraphene.waitElement(By.className("hottextInteraction"), browser);
By checkBy = By.xpath("//div[contains(@class,'hottextInteraction')]//p/span[@class='hottext'][" + index + "]/input[@type='checkbox']"); By checkBy = By.xpath("//div[contains(@class,'hottextInteraction')]//p/span[@class='hottext'][" + index + "]/input[@type='checkbox']");
...@@ -303,6 +333,21 @@ public class QTI21Page { ...@@ -303,6 +333,21 @@ public class QTI21Page {
return this; return this;
} }
/**
* Select the gap match
*
* @param source The row to check
* @param target Text in the target
* @param match Select or deselect
* @return Itself
*/
public QTI21Page answerGapMatch(int row, String target, boolean match) {
By matchBy = By.xpath("//div[contains(@class,'gapMatchInteraction')]/table//tr[th[contains(text(),'" + row + "')]]/td[count(//div[contains(@class,'gapMatchInteraction')]/table//tr/th[text()[contains(.,'" + target + "')]]/preceding-sibling::th)]/input");
WebElement matchEl = browser.findElement(matchBy);
OOGraphene.check(matchEl, match);
return this;
}
/** /**
* Use the click and drop. * Use the click and drop.
* *
...@@ -321,6 +366,75 @@ public class QTI21Page { ...@@ -321,6 +366,75 @@ public class QTI21Page {
return this; return this;
} }
/**
* Select the point based on coordinates.
*
* @param x The x coordinate
* @param y The y coordinate
* @return Itself
*/
public QTI21Page answerSelectPoint(int x, int y) {
By canvasBy = By.xpath("//div[contains(@class,'selectPointInteraction')]/div/canvas");
WebElement canvasEl = browser.findElement(canvasBy);
new Actions(browser)
.moveToElement(canvasEl, x, y)
.click()
.build()
.perform();
return this;
}
/**
* Select the object by its index (start with 0) and
* move it on the image and the specified coodinates.
*
* @param index The index of the object
* @param x The x target coordinate
* @param y The y target coordinate
* @return Itself
*/
public QTI21Page answerPositionObject(int index, int x, int y) {
By itemBy = By.xpath("//div[contains(@class,'positionObjectStage')]//div[@id='object-item-" + index + "']");
OOGraphene.waitElement(itemBy, browser);
WebElement itemEl = browser.findElement(itemBy);
By targetBy = By.xpath("//div[@class='positionObjectStage']//img[contains(@id,'qtiworks_id_container_')]");
WebElement targetEl = browser.findElement(targetBy);
new Actions(browser)
.moveToElement(itemEl, 5, 5)
.clickAndHold()
.moveToElement(targetEl, x, y)
.release()
.build()
.perform();
return this;
}
/**
* Select the point based on coordinates.
*
* @param x The x coordinate
* @return Itself
*/
public QTI21Page answerVerticalSlider(int val) {
By sliderBy = By.xpath("//div[contains(@class,'sliderInteraction')]/div[contains(@class,'sliderVertical')]/div[contains(@class,'sliderWidget')]");
OOGraphene.waitElement(sliderBy, browser);
WebElement sliderEl = browser.findElement(sliderBy);
Dimension size = sliderEl.getSize();
float height = (size.getHeight() / 100f) * val;
float scaledY = size.getHeight() - height;
new Actions(browser)
.moveToElement(sliderEl, 5, Math.round(scaledY))
.click()
.build()
.perform();
By valueBy = By.xpath("//div[contains(@class,'sliderInteraction')]/div[contains(@class,'sliderVertical')]/div[contains(@class,'sliderValue')]/span[text()='" + val + "']");
OOGraphene.waitElement(valueBy, browser);
return this;
}
public QTI21Page answerUpload(File file) { public QTI21Page answerUpload(File file) {
By inputBy = By.cssSelector(".uploadInteraction input[type='file']"); By inputBy = By.cssSelector(".uploadInteraction input[type='file']");
OOGraphene.uploadFile(inputBy, file, browser); OOGraphene.uploadFile(inputBy, file, browser);
......
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment