E2E testing
A sample videoconferencing applications (backend+media server+db) is started automatically. The test exercises the videoconferencing features through the UI by means of a couple of browsers. Logs, metrics and videos are collected automatically.
docker run --rm -v ~/.elastest:/data -v /var/run/docker.sock:/var/run/docker.sock elastest/platform start
Recommended system specifications
ElasTest needs some minimum system specifications in order to run smoothly:
Processor | 1GHz or faster |
RAM | 16GB |
SWAP | 4GB (if RAM < 16GB) |
Hard Disk | 30GB |
Test
@Tag("e2e")
@DisplayName("E2E tests for FullTeaching REST CRUD operations")
@ExtendWith(SeleniumExtension.class)
public class FullTeachingTestE2EREST extends FullTeachingTestE2E {
private static String BROWSER;
final String TEST_COURSE = "TEST_COURSE";
final String TEST_COURSE_INFO = "TEST_COURSE_INFO";
final String EDITED = " EDITED";
final String TEACHER_MAIL = "teacher@gmail.com";
final String TEACHER_PASS = "pass";
final String TEACHER_NAME = "Teacher Cheater";
String COURSE_NAME = TEST_COURSE;
static Exception ex = null;
BrowserUser user;
public FullTeachingTestE2EREST() {
super();
}
/*** ClassRule methods ***/
@BeforeAll()
static void setupAll() {
BROWSER = System.getenv("BROWSER");
if ((BROWSER == null) || (!BROWSER.equals(FIREFOX))) {
BROWSER = CHROME;
}
log.info("Using URL {} to connect to openvidu-testapp", APP_URL);
}
@BeforeEach
void setup(TestInfo info) {
log.info("##### Start test: " + info.getTestMethod().get().getName());
loginTeacher(info); // Teacher login
addCourse(COURSE_NAME); // Add test course
}
@AfterEach
void dispose(TestInfo info) {
try {
this.deleteCourseIfExist();
this.logout(user);
user.dispose();
} finally {
log.info("##### Finish test: " + info.getTestMethod().get().getName());
}
}
/*** Test methods ***/
@Test
void courseRestOperations() throws Exception {
// Edit course
log.info("Editing course");
COURSE_NAME = COURSE_NAME + EDITED;
List<WebElement> l = user.getDriver().findElements(By.className("course-put-icon"));
openDialog(l.get(l.size() - 1), user);
user.waitUntil(ExpectedConditions.elementToBeClickable(By.id(("input-put-course-name"))),
"Input for course name not clickable");
user.getDriver().findElement(By.id("input-put-course-name")).clear();
user.getDriver().findElement(By.id("input-put-course-name")).sendKeys(COURSE_NAME);
user.getDriver().findElement(By.id("submit-put-course-btn")).click();
waitForDialogClosed("course-modal", "Edition of course failed", user);
user.waitUntil(
ExpectedConditions.textToBe(
By.cssSelector("#course-list .course-list-item:last-child div.course-title span"), COURSE_NAME),
"Unexpected course name");
}
....
We can observe the all code in this link.
The enpoint for the application is defined in the FullTrachingTestE2E
class. In the next box we observe the block of code that define the endpoint. we can observe the complete code in this link.
public FullTeachingTestE2E() {
if (System.getenv("ET_EUS_API") == null) {
// Outside ElasTest
ChromeDriverManager.getInstance().setup();
FirefoxDriverManager.getInstance().setup();
}
if (System.getenv("ET_SUT_HOST") != null) {
APP_URL = "https://" + System.getenv("ET_SUT_HOST") + ":5000/";
} else {
APP_URL = System.getProperty("app.url");
if (APP_URL == null) {
APP_URL = "https://localhost:5000/";
}
}
}
ET_SUT_HOST
,ET_SUT_PORT
variables will be the IP and port of our SuT respectively. (Know more about Environment Variables)
Jenkins
node{
def sutIp
elastest(tss: ['EUS'], surefireReportsPattern: '**/target/surefire-reports/TEST-*.xml', monitoring: true, project: 'Jenkins Examples') {
stage("Setting environment") {
echo 'Environment variables'
sh "env"
git "https://github.com/elastest/full-teaching-experiment.git"
}
try {
stage("Start Sut") {
sh "cd docker-compose/full-teaching-without-network; export BUG_TAG=demo; docker-compose --no-ansi -p ${env.ET_SUT_CONTAINER_NAME} up -d"
sutContainerName = env.ET_SUT_CONTAINER_NAME + "_full-teaching_1";
sutNetwork = getFirstNetwork(sutContainerName)
sutIp = containerIp(sutContainerName,network)
echo 'Sut ip: '+ sutIp
sh 'docker run -e IP=' + sutIp + ' -e PORT=5001 --network=' + sutNetwork + ' elastest/etm-check-service-up'
}
stage("Run Tests") {
echo 'Running test'
mvnHome = tool 'M3.3.9'
sh "'${mvnHome}/bin/mvn' -Dapp.url=https://" + sutIp +":5001/ -Dtest=FullTeachingTestE2EREST -B -DforkCount=0 test"
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
} finally {
echo 'Stopping SUT'
sh "cd docker-compose/full-teaching-env; docker-compose --no-ansi -p ${env.ET_SUT_CONTAINER_NAME} down"
}
}
}
def getFirstNetwork(containerName) {
echo "Inside getFirstNetwork function"
network = sh (
script: "docker inspect " + containerName + " -f \"{{json .NetworkSettings.Networks}}\" | awk \"{sub(/:.*/,\\\"\\\")}1\" | awk \"{sub(/\\\"/,\\\"\\\")}1\" | awk \"{sub(/\\\"/,\\\"\\\")}1\" | awk \"{sub(/{/,\\\"\\\")}1\"",
returnStdout: true
).trim()
echo containerName+" Network = " + network;
return network;
}
def containerIp(containerName, network) {
echo "Inside containerIp function"
containerIp = sh (
script: "docker inspect --format=\"{{.NetworkSettings.Networks." + network + ".IPAddress}}\" "+ containerName,
returnStdout: true
).trim()
echo containerName+" IP = " + containerIp;
return containerIp;
}