Skip to content

Commit

Permalink
updated js test
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecupa committed Sep 23, 2023
1 parent 04e44a9 commit 1d8ab63
Show file tree
Hide file tree
Showing 5 changed files with 3,284 additions and 166 deletions.
3 changes: 1 addition & 2 deletions Tests/OpenviduTests/src/test/java/OpenViduHelloWordTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ void setup() {
driverFirefox.get(URL);

NAMESESSION = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "NAMESESSION");
//TESTNAME = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "TestName");
XpathJoinButton = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "XpathJoinButton");
XpathJoinButton = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "XpathJoinButton");
xpathLeaveButton = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "xpathLeaveButton");
xpathOtherCamera = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "xpathOtherCamera");
idHeader = readVariablesFromExcel(testLocation, "OpenViduHelloWordTest", "idHeader");
Expand Down
227 changes: 138 additions & 89 deletions Tests/OpenviduTests/src/test/java/openViduJsTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.NoSuchElementException;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -20,6 +17,7 @@
import com.aventstack.extentreports.ExtentTest;

import Reporter.ExtentManager;
import io.netty.handler.timeout.TimeoutException;

/**
* Test with Java.
Expand All @@ -31,6 +29,14 @@ class OpenViduJsTest extends Module{
String testLocation = "test-input/Parameters.xlsx";
String reportLocation = "OpenViduJsTestTestReport.html";

String[] readyStateValues = {
"HAVE_NOTHING",
"HAVE_METADATA",
"HAVE_CURRENT_DATA",
"HAVE_FUTURE_DATA",
"HAVE_ENOUGH_DATA"
};

private ExtentTest test;
public static ExtentReports extentReports;
static ExtentManager e = new ExtentManager();
Expand Down Expand Up @@ -58,10 +64,13 @@ public OpenViduJsTest() {
}

/**
* BeforeEach.
* BeforeEach
*
* @author Andrea Acuña
* Description: Execute before every single test. Configure the camera an set de url in each browser
* Description: Execute before every single test.
* Configure the camera
* Set de url in each browser
* Read the variables from excel file
*/
@BeforeEach
void setup() {
Expand All @@ -73,7 +82,6 @@ void setup() {
driverFirefox.get(URL);

NAMESESSION = readVariablesFromExcel(testLocation, "OpenViduJsTest", "NAMESESSION");
TESTNAME = readVariablesFromExcel(testLocation, "OpenViduJsTest", "TESTNAME");
XpathJoinButton = readVariablesFromExcel(testLocation, "OpenViduJsTest", "XpathJoinButton");
idLeaveButton = readVariablesFromExcel(testLocation, "OpenViduJsTest", "idLeaveButton");
xpathOtherCamera = readVariablesFromExcel(testLocation, "OpenViduJsTest", "xpathOtherCamera");
Expand All @@ -83,14 +91,13 @@ void setup() {
}

/**
* Test with Java.
* Test with Java -> T001_JoinSession
*
* @author Andrea Acuña
* Description: Join the session and verificate that the two browsers are inside the session
* @throws IOException
* Description: Join the session and verification that both browsers are inside the session
*/
@Test
void T001_JoinSession() throws IOException {
void T001_JoinSession(){

TESTNAME = new Throwable().getStackTrace()[0].getMethodName();
test = e.startTest(TESTNAME, "Join the session and verifies that the two browsers are inside the session", extentReports);
Expand Down Expand Up @@ -132,23 +139,28 @@ void T001_JoinSession() throws IOException {

}

}catch (NoSuchElementException n){

e.addStepWithoutCapture(test, "FAIL", "General error is occur");
fail("The app is not correctly inicializate");
}catch (TimeoutException n){

e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + n.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + n.getMessage());
fail("The app is not correctly inicializate. There are a TimeoutException: " + n.getMessage());

}catch (Exception ex) {

e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + ex.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + ex.getMessage());
fail("An unexpected exception occurred: " + ex.getMessage());
}
}

/**
* Test with Java.
* Test with Java -> T002_LeaveSession
*
* @author Andrea Acuña
* Description: Join the session, verficate that the video is playing property and leave the session
* @throws IOException
* @throws InterruptedException
* Description: verification that the video is playing property and both browsers leaves the session correctly
*/
@Test
void T002_LeaveSession() throws IOException, InterruptedException{
void T002_LeaveSession(){

TESTNAME = new Throwable().getStackTrace()[0].getMethodName();
test = e.startTest(TESTNAME, "Join the session, verifies that the video is playing property and leave the session", extentReports);
Expand All @@ -160,36 +172,60 @@ void T002_LeaveSession() throws IOException, InterruptedException{
textBox.clear();
textBox.sendKeys(NAMESESSION);
WebElement joinButtonC = driverChrome.findElement(By.xpath(XpathJoinButton));
joinButtonC.submit();
joinButtonC.click();

//Configurate de session in firefox
WebElement textBoxF = driverFirefox.findElement(By.id(idNameSession));
textBoxF.clear();
textBoxF.sendKeys(NAMESESSION);
WebElement joinButtonF = driverFirefox.findElement(By.xpath(XpathJoinButton));
joinButtonF.submit();
joinButtonF.click();

try{
// see if the video is playing properly, moreover synchronize both videos
WebDriverWait waitC = new WebDriverWait(driverChrome, Duration.ofSeconds(30));
waitC.until(ExpectedConditions.elementToBeClickable(By.xpath(xpathOtherCamera)));
waitC.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathOtherCamera)));

WebDriverWait waitF = new WebDriverWait(driverFirefox, Duration.ofSeconds(30));
waitF.until(ExpectedConditions.elementToBeClickable(By.xpath(xpathOtherCamera)));
waitF.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpathOtherCamera)));

driverChrome.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driverFirefox.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

// see if the video is playing properly
String currentTimeChrome= driverChrome.findElement(By.id(idSelfCamera)).getAttribute("duration");
String currentTimeFirefox = driverFirefox.findElement(By.id(idSelfCamera)).getAttribute("duration");

assertNotEquals(currentTimeChrome, "NaN");
assertNotEquals(currentTimeFirefox, "NaN");

e.addStep(test, "INFO", driverChrome, "Session configurated in Chrome with session name: " + NAMESESSION);
e.addStep(test, "INFO", driverFirefox, "Session configurated in Firefox with session name: " + NAMESESSION);
String SelfCurrentTimeChrome = driverChrome.findElement(By.id(idSelfCamera)).getAttribute("readyState");
String SelfCurrentTimeFirefox = driverFirefox.findElement(By.id(idSelfCamera)).getAttribute("readyState");

if (Integer.parseInt(SelfCurrentTimeChrome) >= 3 && Integer.parseInt(SelfCurrentTimeChrome) < readyStateValues.length) {
e.addStep(test, "INFO", driverChrome, "Self video is correctly playing in Chrome: " + readyStateValues[Integer.parseInt(SelfCurrentTimeChrome)]);
} else {
e.addStep(test, "FAIL", driverChrome, "Self video is NOT correctly playing in Chrome: " + readyStateValues[Integer.parseInt(SelfCurrentTimeChrome)]);
}

if (Integer.parseInt(SelfCurrentTimeFirefox) >= 3 && Integer.parseInt(SelfCurrentTimeFirefox) < readyStateValues.length) {
e.addStep(test, "INFO", driverFirefox, "Self video is correctly playing in Firefox: " + readyStateValues[Integer.parseInt(SelfCurrentTimeFirefox)]);
} else {
e.addStep(test, "FAIL", driverFirefox, "Self video is NOT correctly playing in Firefox: " + readyStateValues[Integer.parseInt(SelfCurrentTimeFirefox)]);
}

waitC.until(ExpectedConditions.visibilityOfElementLocated(By.id(idSelfCamera)));
waitF.until(ExpectedConditions.visibilityOfElementLocated(By.id(idSelfCamera)));

String OtherCurrentTimeChrome = driverChrome.findElement(By.xpath(xpathOtherCamera)).getAttribute("readyState");
String OtherCurrentTimeFirefox = driverFirefox.findElement(By.xpath(xpathOtherCamera)).getAttribute("readyState");

if (Integer.parseInt(OtherCurrentTimeChrome) >= 3 && Integer.parseInt(OtherCurrentTimeChrome) < readyStateValues.length) {
e.addStep(test, "INFO", driverChrome, "Other video is correctly playing in Chrome: " + readyStateValues[Integer.parseInt(OtherCurrentTimeChrome)]);
} else {
e.addStep(test, "FAIL", driverChrome, "Other video is NOT correctly playing in Chrome: " + readyStateValues[Integer.parseInt(SelfCurrentTimeChrome)]);
}

if (Integer.parseInt(OtherCurrentTimeFirefox) >= 3 && Integer.parseInt(OtherCurrentTimeFirefox) < readyStateValues.length) {
e.addStep(test, "INFO", driverFirefox, "Other video is correctly playing in Firefox: " + readyStateValues[Integer.parseInt(OtherCurrentTimeFirefox)]);
} else {
e.addStep(test, "FAIL", driverFirefox, "Other video is NOT correctly playing in Firefox: " + readyStateValues[Integer.parseInt(OtherCurrentTimeFirefox)]);
}

//Leave the session with chrome
WebElement leaveButtonC = driverChrome.findElement(By.id(idLeaveButton));
if (leaveButtonC.isDisplayed()){
Expand Down Expand Up @@ -228,80 +264,93 @@ void T002_LeaveSession() throws IOException, InterruptedException{

e.addStep(test, "PASS", driverChrome, "TEST: " + TESTNAME +" ok: Session correctly leave in both drivers");

}catch (NoSuchElementException n){
}catch (TimeoutException n){

e.addStepWithoutCapture(test, "FAIL", "General error is occur");
fail("The app is not correctly inicializate");
}
e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + n.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + n.getMessage());
fail("The app is not correctly inicializate. There are a TimeoutException: " + n.getMessage());

}catch (Exception ex) {

e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + ex.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + ex.getMessage());
fail("An unexpected exception occurred: " + ex.getMessage());
}
}

/**
* Test with Java.
* Test with Java -> T003_SessionHeader
*
* @author Andrea Acuña
* Description: Joins the session and verifies that the session name is correct
* @throws IOException
* Description: Joins the session and verifies that the session name is the expected
*/
@Test
void T003_SessionHeader() throws IOException {

TESTNAME = new Throwable().getStackTrace()[0].getMethodName();
test = e.startTest(TESTNAME, "Joins the session and verifies that the session name is correct", extentReports);

e.addStepWithoutCapture(test, "INFO", "Starting test " + TESTNAME);

// Configurate the session in chrome
WebElement textBox = driverChrome.findElement(By.id(idNameSession));
textBox.clear();
textBox.sendKeys(NAMESESSION);
WebElement joinButtonC = driverChrome.findElement(By.xpath(XpathJoinButton));
joinButtonC.submit();

try{
WebDriverWait waitC = new WebDriverWait(driverChrome, Duration.ofSeconds(30));
waitC.until(ExpectedConditions.elementToBeClickable(By.id(idHeader)));

if (!driverChrome.findElements(By.id(idHeader)).isEmpty()){

if (NAMESESSION.equals(driverChrome.findElement(By.id(idHeader)).getText())){
e.addStep(test, "INFO", driverChrome, "The header text is correct: " + NAMESESSION);
@Test
void T003_SessionHeader(){

TESTNAME = new Throwable().getStackTrace()[0].getMethodName();
test = e.startTest(TESTNAME, "Joins the session and verifies that the session name is correct", extentReports);

e.addStepWithoutCapture(test, "INFO", "Starting test " + TESTNAME);

// Configurate the session in chrome
WebElement textBox = driverChrome.findElement(By.id(idNameSession));
textBox.clear();
textBox.sendKeys(NAMESESSION);
WebElement joinButtonC = driverChrome.findElement(By.xpath(XpathJoinButton));
joinButtonC.submit();

try{
WebDriverWait waitC = new WebDriverWait(driverChrome, Duration.ofSeconds(30));
waitC.until(ExpectedConditions.elementToBeClickable(By.id(idHeader)));

if (!driverChrome.findElements(By.id(idHeader)).isEmpty()){

if (NAMESESSION.equals(driverChrome.findElement(By.id(idHeader)).getText())){
e.addStep(test, "INFO", driverChrome, "The header text is correct: " + NAMESESSION);
}else{
e.addStep(test, "FAIL", driverChrome, "The header it should be: " + NAMESESSION + "but is: " + driverChrome.findElement(By.id(idHeader)).getText());
fail("Test fail");
}
}else{
e.addStep(test, "FAIL", driverChrome, "The header it should be: " + NAMESESSION + "but is: " + driverChrome.findElement(By.id(idHeader)).getText());
e.addStep(test, "FAIL", driverChrome, "The header it should be: " + NAMESESSION + "but is blank");
fail("Test fail");
}
}else{
e.addStep(test, "FAIL", driverChrome, "The header it should be: " + NAMESESSION + "but is blank");
fail("Test fail");
}
e.addStep(test, "PASS", driverChrome, "TEST: " + TESTNAME +" ok: Session name is: " + NAMESESSION);
e.addStep(test, "PASS", driverChrome, "TEST: " + TESTNAME +" ok: Session name is: " + NAMESESSION);

}catch (TimeoutException n){

}catch (NoSuchElementException n){
e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + n.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + n.getMessage());
fail("The app is not correctly inicializate. There are a TimeoutException: " + n.getMessage());

e.addStepWithoutCapture(test, "FAIL", "General error is occur");
fail("The app is not correctly inicializate");
}catch (Exception ex) {

e.addStep(test, "FAIL", driverChrome, "Error in chrome: " + ex.getMessage());
e.addStep(test, "FAIL", driverFirefox, "Error in firefox: " + ex.getMessage());
fail("An unexpected exception occurred: " + ex.getMessage());
}
}
}

/**
* AfterEach.
*
* @author Andrea Acuña
* Description: close both drivers
*/
@AfterEach
void quit(){
super.quitTwoBrowsers(driverChrome, driverFirefox);
}
* AfterEach.
*
* @author Andrea Acuña
* Description: close both drivers correctly after every single test
*/
@AfterEach
void quit(){
super.quitTwoBrowsers(driverChrome, driverFirefox);
}

/**
* AfterAll.
*
* @author Andrea Acuña
* Description: Close and generate the report
*/
@AfterAll
public static void tearDown() {
e.tearDownExtent(extentReports);
}
* AfterAll.
*
* @author Andrea Acuña
* Description: Close and generate the report after execution of all tests
*/
@AfterAll
public static void tearDown() {
e.tearDownExtent(extentReports);
}

}
12 changes: 11 additions & 1 deletion Tests/OpenviduTests/target/surefire-reports/OpenViduJsTest.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
-------------------------------------------------------------------------------
Test set: OpenViduJsTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 36.872 s - in OpenViduJsTest
Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 81.333 s <<< FAILURE! - in OpenViduJsTest
T003_SessionHeader Time elapsed: 59.727 s <<< FAILURE!
org.opentest4j.AssertionFailedError:
An unexpected exception occurred: Expected condition failed: waiting for element to be clickable: By.id: session-header (tried for 30 second(s) with 500 milliseconds interval)
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 117.0.5938.88, chrome: {chromedriverVersion: 117.0.5938.92 (67649b10b92b..., userDataDir: C:\Users\Usuario\AppData\Lo...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:56763}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: WINDOWS, proxy: Proxy(), se:cdp: ws://localhost:56763/devtoo..., se:cdpVersion: 117.0.5938.88, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 780a4191df176d3f5921296385a86d76
at OpenViduJsTest.T003_SessionHeader(OpenViduJsTest.java:330)

Loading

0 comments on commit 1d8ab63

Please sign in to comment.