List of usage examples for org.openqa.selenium Keys ENTER
Keys ENTER
To view the source code for org.openqa.selenium Keys ENTER.
Click Source Link
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Signal message") void oneToManySignalMessage() throws Exception { setupBrowser("chrome"); log.info("Signal message"); WebElement addUser = user.getDriver().findElement(By.id("add-user-btn")); for (int i = 0; i < 4; i++) { addUser.click();// w w w . java2 s . co m } user.getDriver().findElements(By.className("publish-checkbox")).forEach(el -> el.click()); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 16); user.getDriver().findElements(By.className(("message-btn"))).get(0).click(); user.getEventManager().waitUntilEventReaches("signal:chat", 4); gracefullyLeaveParticipants(4); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Subscribe Unsubscribe") void subscribeUnsubscribeTest() throws Exception { setupBrowser("chrome"); log.info("Subscribe Unsubscribe"); user.getDriver().findElement(By.id("one2one-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .publish-checkbox")).click(); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); // Global unsubscribe-subscribe WebElement subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 video")); WebElement subBtn = user.getDriver().findElement(By.cssSelector(("#openvidu-instance-0 .sub-btn"))); subBtn.click();/* w ww . j av a 2 s . co m*/ user.getWaiter().until( ExpectedConditions.not(ExpectedConditions.attributeToBeNotEmpty(subscriberVideo, "srcObject"))); Assert.assertFalse("Subscriber video should not have srcObject defined after unsubscribe", user.getEventManager().hasMediaStream(subscriberVideo, "#openvidu-instance-0")); subBtn.click(); user.getEventManager().waitUntilEventReaches("streamPlaying", 3); numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); // Video unsubscribe subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 video")); Iterable<WebElement> firstVideo = Arrays.asList(subscriberVideo); user.getDriver().findElement(By.cssSelector(("#openvidu-instance-0 .sub-video-btn"))).click(); Thread.sleep(1000); Assert.assertTrue("Subscriber video was expected to only have audio track", user.getEventManager().assertMediaTracks(firstVideo, true, false)); // Audio unsubscribe user.getDriver().findElement(By.cssSelector(("#openvidu-instance-0 .sub-audio-btn"))).click(); Thread.sleep(1000); Assert.assertTrue("Subscriber video was expected to not have video or audio tracks", user.getEventManager().assertMediaTracks(firstVideo, false, false)); // Video and audio subscribe user.getDriver().findElement(By.cssSelector(("#openvidu-instance-0 .sub-video-btn"))).click(); Thread.sleep(1000); Assert.assertTrue("Subscriber video was expected to only have video track", user.getEventManager().assertMediaTracks(firstVideo, false, true)); user.getDriver().findElement(By.cssSelector(("#openvidu-instance-0 .sub-audio-btn"))).click(); Thread.sleep(1000); Assert.assertTrue("Subscriber video was expected to have audio and video tracks", user.getEventManager().assertMediaTracks(firstVideo, true, true)); gracefullyLeaveParticipants(2); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Moderator capabilities") void moderatorCapabilitiesTest() throws Exception { setupBrowser("chrome"); log.info("Moderator capabilities"); // Add publisher user.getDriver().findElement(By.id("add-user-btn")).click(); // Add subscriber user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .publish-checkbox")).click(); // Add and configure moderator (only subscribe) user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-2 .publish-checkbox")).click(); user.getDriver().findElement(By.id("session-settings-btn-2")).click(); Thread.sleep(1000);//from w w w . ja v a 2 s. c o m user.getDriver().findElement(By.id("radio-btn-mod")).click(); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 9); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 3); user.getEventManager().waitUntilEventReaches("streamPlaying", 3); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 3 videos but found " + numberOfVideos, 3, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); // Moderator forces unpublish user.getDriver().findElement(By.cssSelector("#openvidu-instance-2 .force-unpub-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 3); List<WebElement> videos = user.getDriver().findElements(By.tagName("video")); numberOfVideos = videos.size(); Assert.assertEquals("Expected 1 video but found " + numberOfVideos, 1, numberOfVideos); Assert.assertFalse("Publisher video should not have srcObject defined after force unpublish", user.getEventManager().hasMediaStream(videos.get(0), "")); // Publisher publishes again user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-btn")).click(); user.getEventManager().waitUntilEventReaches("streamCreated", 6); user.getEventManager().waitUntilEventReaches("streamPlaying", 6); numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 3 videos but found " + numberOfVideos, 3, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); // Moderator forces disconnect of publisher user.getDriver().findElement(By.cssSelector("#openvidu-instance-2 .force-disconnect-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 6); user.getEventManager().waitUntilEventReaches("connectionDestroyed", 2); user.getEventManager().waitUntilEventReaches("sessionDisconnected", 1); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 0)); gracefullyLeaveParticipants(3); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Stream property changed event") void streamPropertyChangedEventTest() throws Exception { Queue<Boolean> threadAssertions = new ConcurrentLinkedQueue<Boolean>(); setupBrowser("chromeAlternateScreenShare"); log.info("Stream property changed event"); WebElement oneToManyInput = user.getDriver().findElement(By.id("one2many-input")); oneToManyInput.clear();/*www .j a v a 2 s . c om*/ oneToManyInput.sendKeys("1"); user.getDriver().findElement(By.id("one2many-btn")).click(); user.getDriver().findElement(By.className("screen-radio")).click(); List<WebElement> joinButtons = user.getDriver().findElements(By.className("join-btn")); for (WebElement el : joinButtons) { el.sendKeys(Keys.ENTER); } user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); // Unpublish video final CountDownLatch latch1 = new CountDownLatch(2); user.getEventManager().on("streamPropertyChanged", (event) -> { threadAssertions.add("videoActive".equals(event.get("changedProperty").getAsString())); threadAssertions.add(!event.get("newValue").getAsBoolean()); latch1.countDown(); }); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-video-btn")).click(); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2); if (!latch1.await(5000, TimeUnit.MILLISECONDS)) { gracefullyLeaveParticipants(2); fail(); return; } user.getEventManager().off("streamPropertyChanged"); log.info("Thread assertions: {}", threadAssertions.toString()); for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) { Assert.assertTrue("Some Event property was wrong", iter.next()); iter.remove(); } // Unpublish audio final CountDownLatch latch2 = new CountDownLatch(2); user.getEventManager().on("streamPropertyChanged", (event) -> { threadAssertions.add("audioActive".equals(event.get("changedProperty").getAsString())); threadAssertions.add(!event.get("newValue").getAsBoolean()); latch2.countDown(); }); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-audio-btn")).click(); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4); if (!latch2.await(5000, TimeUnit.MILLISECONDS)) { gracefullyLeaveParticipants(2); fail(); return; } user.getEventManager().off("streamPropertyChanged"); log.info("Thread assertions: {}", threadAssertions.toString()); for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) { Assert.assertTrue("Some Event property was wrong", iter.next()); iter.remove(); } // Resize captured window final CountDownLatch latch3 = new CountDownLatch(2); int newWidth = 1000; int newHeight = 700; final long[] expectedWidthHeight = new long[2]; user.getEventManager().on("streamPropertyChanged", (event) -> { String expectedDimensions = "{\"width\":" + expectedWidthHeight[0] + ",\"height\":" + expectedWidthHeight[1] + "}"; threadAssertions.add("videoDimensions".equals(event.get("changedProperty").getAsString())); threadAssertions.add(expectedDimensions.equals(event.get("newValue").getAsJsonObject().toString())); latch3.countDown(); }); user.getDriver().manage().window().setSize(new Dimension(newWidth, newHeight)); String widthAndHeight = user.getEventManager().getDimensionOfViewport(); JSONObject obj = (JSONObject) new JSONParser().parse(widthAndHeight); expectedWidthHeight[0] = (long) obj.get("width"); expectedWidthHeight[1] = (long) obj.get("height"); System.out.println("New viewport dimension: " + obj.toJSONString()); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6); if (!latch3.await(5000, TimeUnit.MILLISECONDS)) { gracefullyLeaveParticipants(2); fail(); return; } user.getEventManager().off("streamPropertyChanged"); log.info("Thread assertions: {}", threadAssertions.toString()); for (Iterator<Boolean> iter = threadAssertions.iterator(); iter.hasNext();) { Assert.assertTrue("Some Event property was wrong", iter.next()); iter.remove(); } gracefullyLeaveParticipants(2); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Remote record cross-browser audio-only and video-only") void remoteRecordAudioOnlyVideoOnlyTest() throws Exception { isRecordingTest = true;/*from w w w. j a va 2 s .c o m*/ setupBrowser("chromeAlternateScreenShare"); log.info("Remote record cross-browser audio-only and video-only"); final String SESSION_NAME = "TestSession"; final String RECORDING_COMPOSED_VIDEO = "COMPOSED_VIDEO_ONLY"; final String RECORDING_COMPOSED_AUDIO = "COMPOSED_AUDIO_ONLY"; final String RECORDING_INDIVIDUAL_VIDEO = "INDIVIDUAL_VIDEO_ONLY"; final String RECORDING_INDIVIDUAL_AUDIO = "INDIVIDUAL_AUDIO_ONLY"; final int RECORDING_DURATION = 5000; Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { System.out.println("Uncaught exception: " + ex); synchronized (lock) { OpenViduTestAppE2eTest.ex = new Exception(ex); } } }; Thread t = new Thread(() -> { MyUser user2 = new MyUser(new FirefoxUser("FirefoxUser", 30)); otherUsers.add(user2); user2.getDriver().get(APP_URL); WebElement urlInput = user2.getDriver().findElement(By.id("openvidu-url")); urlInput.clear(); urlInput.sendKeys(OPENVIDU_URL); WebElement secretInput = user2.getDriver().findElement(By.id("openvidu-secret")); secretInput.clear(); secretInput.sendKeys(OPENVIDU_SECRET); user2.getEventManager().startPolling(); // Firefox user audio + video user2.getDriver().findElement(By.id("add-user-btn")).click(); // Firefox user video-only user2.getDriver().findElement(By.id("add-user-btn")).click(); user2.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .send-audio-checkbox")).click(); // Join Firefox users user2.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); try { user2.getEventManager().waitUntilEventReaches("connectionCreated", 8); user2.getEventManager().waitUntilEventReaches("accessAllowed", 2); user2.getEventManager().waitUntilEventReaches("streamCreated", 8); user2.getEventManager().waitUntilEventReaches("streamPlaying", 8); int nVideos = user2.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 8 videos in Firefox user but found " + nVideos, 8, nVideos); user2.getEventManager().waitUntilEventReaches("recordingStarted", 2); user2.getEventManager().waitUntilEventReaches("recordingStopped", 2); user2.getEventManager().waitUntilEventReaches("recordingStarted", 4); user2.getEventManager().waitUntilEventReaches("recordingStopped", 4); user2.getEventManager().waitUntilEventReaches("recordingStarted", 6); user2.getEventManager().waitUntilEventReaches("recordingStopped", 6); user2.getEventManager().waitUntilEventReaches("recordingStarted", 8); user2.getEventManager().waitUntilEventReaches("recordingStopped", 8); user2.getEventManager().waitUntilEventReaches("streamDestroyed", 4); user2.getEventManager().waitUntilEventReaches("connectionDestroyed", 4); user2.getDriver().findElement(By.id("remove-user-btn")).click(); user2.getDriver().findElement(By.id("remove-user-btn")).click(); user2.getEventManager().waitUntilEventReaches("sessionDisconnected", 2); } catch (Exception e) { e.printStackTrace(); user2.dispose(); Thread.currentThread().interrupt(); } user2.dispose(); }); t.setUncaughtExceptionHandler(h); t.start(); // Chrome user screen share only-video user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .screen-radio")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .send-audio-checkbox")).click(); // Chrome user audio-only user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .send-video-checkbox")).click(); // Join Chrome users user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 8); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 8); user.getEventManager().waitUntilEventReaches("streamPlaying", 8); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 8 videos but found " + numberOfVideos, 8, numberOfVideos); user.getDriver().findElement(By.id("session-api-btn-0")).click(); Thread.sleep(1000); user.getDriver().findElement(By.id("rec-properties-btn")).click(); Thread.sleep(500); WebElement recordingNameField = user.getDriver().findElement(By.id("recording-name-field")); // Video-only COMPOSED recording recordingNameField.clear(); recordingNameField.sendKeys(RECORDING_COMPOSED_VIDEO); user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("start-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording started [" + SESSION_NAME + "]")); user.getEventManager().waitUntilEventReaches("recordingStarted", 2); Thread.sleep(RECORDING_DURATION); user.getDriver().findElement(By.id("recording-id-field")).clear(); user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME); user.getDriver().findElement(By.id("stop-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording stopped [" + SESSION_NAME + "]")); user.getEventManager().waitUntilEventReaches("recordingStopped", 2); // Audio-only COMPOSED recording recordingNameField.clear(); recordingNameField.sendKeys(RECORDING_COMPOSED_AUDIO); user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click(); user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("start-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording started [" + SESSION_NAME + "-1]")); user.getEventManager().waitUntilEventReaches("recordingStarted", 4); Thread.sleep(RECORDING_DURATION); user.getDriver().findElement(By.id("recording-id-field")).clear(); user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-1"); user.getDriver().findElement(By.id("stop-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording stopped [" + SESSION_NAME + "-1]")); user.getEventManager().waitUntilEventReaches("recordingStopped", 4); // Video-only INDIVIDUAL recording recordingNameField.clear(); recordingNameField.sendKeys(RECORDING_INDIVIDUAL_VIDEO); user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click(); user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("rec-outputmode-select")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("option-INDIVIDUAL")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("start-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording started [" + SESSION_NAME + "-2]")); user.getEventManager().waitUntilEventReaches("recordingStarted", 6); Thread.sleep(RECORDING_DURATION); user.getDriver().findElement(By.id("recording-id-field")).clear(); user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-2"); user.getDriver().findElement(By.id("stop-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording stopped [" + SESSION_NAME + "-2]")); user.getEventManager().waitUntilEventReaches("recordingStopped", 6); // Audio-only INDIVIDUAL recording recordingNameField.clear(); recordingNameField.sendKeys(RECORDING_INDIVIDUAL_AUDIO); user.getDriver().findElement(By.id("rec-hasaudio-checkbox")).click(); user.getDriver().findElement(By.id("rec-hasvideo-checkbox")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("start-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording started [" + SESSION_NAME + "-3]")); user.getEventManager().waitUntilEventReaches("recordingStarted", 8); Thread.sleep(RECORDING_DURATION); user.getDriver().findElement(By.id("recording-id-field")).clear(); user.getDriver().findElement(By.id("recording-id-field")).sendKeys(SESSION_NAME + "-3"); user.getDriver().findElement(By.id("stop-recording-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Recording stopped [" + SESSION_NAME + "-3]")); user.getEventManager().waitUntilEventReaches("recordingStopped", 8); String recordingsPath = "/opt/openvidu/recordings/"; // Check video-only COMPOSED recording String recPath = recordingsPath + SESSION_NAME + "/"; Recording recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME); this.checkMultimediaFile(new File(recPath + recording.getName() + ".mp4"), false, true, recording.getDuration(), recording.getResolution(), null, "h264", true); // Check audio-only COMPOSED recording recPath = recordingsPath + SESSION_NAME + "-1/"; recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-1"); this.checkMultimediaFile(new File(recPath + recording.getName() + ".webm"), true, false, recording.getDuration(), null, "opus", null, true); // Check video-only INDIVIDUAL recording recPath = recordingsPath + SESSION_NAME + "-2/"; recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-2"); this.checkIndividualRecording(recPath, recording, 3, "opus", "vp8", true); // Check audio-only INDIVIDUAL recording recPath = recordingsPath + SESSION_NAME + "-3/"; recording = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET).getRecording(SESSION_NAME + "-3"); this.checkIndividualRecording(recPath, recording, 2, "opus", "vp8", true); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); gracefullyLeaveParticipants(2); t.join(); synchronized (lock) { if (OpenViduTestAppE2eTest.ex != null) { throw OpenViduTestAppE2eTest.ex; } } }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Video filter test") void videoFilterTest() throws Exception { setupBrowser("chrome"); log.info("Video filter test"); // Configure publisher user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .subscribe-checkbox")).get(0).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .send-audio-checkbox")).get(0).click(); user.getDriver().findElement(By.id("session-settings-btn-0")).click(); Thread.sleep(1000);//www . j ava2 s . co m user.getDriver().findElement(By.id("add-allowed-filter-btn")).click(); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); // Configure subscriber user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .publish-checkbox")).click(); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have a video only track", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true)); WebElement subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video")); // Analyze Chrome fake video stream without gray filter (GREEN color) Map<String, Long> rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); // Try to apply none allowed filter user.getDriver().findElement(By.cssSelector(".filter-btn")).click(); Thread.sleep(1000); WebElement filterTypeInput = user.getDriver().findElement(By.id("filter-type-field")); filterTypeInput.clear(); filterTypeInput.sendKeys("NotAllowedFilter"); user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Error [You don't have permissions to apply a filter]")); // Try to execute method over not applied filter user.getDriver().findElement(By.id("exec-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "has no filter applied in session")); // Apply allowed video filter filterTypeInput.clear(); filterTypeInput.sendKeys("GStreamerFilter"); WebElement filterOptionsInput = user.getDriver().findElement(By.id("filter-options-field")); filterOptionsInput.clear(); filterOptionsInput.sendKeys("{\"command\": \"videobalance saturation=0.0\"}"); user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter applied")); // Try to apply another filter user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "already has a filter applied in session")); // Analyze Chrome fake video stream with gray filter (GRAY color) user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2); Thread.sleep(500); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average gray", checkVideoAverageRgbGray(rgb)); // Execute filter method WebElement filterMethodInput = user.getDriver().findElement(By.id("filter-method-field")); filterMethodInput.clear(); filterMethodInput.sendKeys("setElementProperty"); WebElement filterParamsInput = user.getDriver().findElement(By.id("filter-params-field")); filterParamsInput.clear(); filterParamsInput.sendKeys("{\"propertyName\":\"saturation\",\"propertyValue\":\"1.0\"}"); user.getDriver().findElement(By.id("exec-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter method executed")); // Analyze Chrome fake video stream without gray filter (GREEN color) user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4); Thread.sleep(500); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); // Publisher leaves and connects with active filter user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 2); user.getEventManager().waitUntilEventReaches("connectionDestroyed", 1); user.getEventManager().waitUntilEventReaches("sessionDisconnected", 1); user.getDriver().findElement(By.id("publisher-settings-btn-0")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(500); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .join-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 7); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); // Analyze Chrome fake video stream with gray filter (GRAY color) subscriberVideo = user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video")); rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average gray", checkVideoAverageRgbGray(rgb)); // Remove filter user.getDriver().findElement(By.cssSelector(".filter-btn")).click(); Thread.sleep(500); user.getDriver().findElement(By.id("remove-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter removed")); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 6); Thread.sleep(1000); // Analyze Chrome fake video stream with gray filter (GREEN color) rgb = user.getEventManager().getAverageRgbFromVideo(subscriberVideo); System.out.println(rgb.toString()); Assert.assertTrue("Video is not average green", checkVideoAverageRgbGreen(rgb)); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); gracefullyLeaveParticipants(2); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Video filter events test") void videoFilterEventsTest() throws Exception { setupChromeWithFakeVideo(Paths.get("/opt/openvidu/barcode.y4m")); log.info("Video filter events test"); // Configure publisher user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .subscribe-checkbox")).get(0).click(); user.getDriver().findElements(By.cssSelector("#openvidu-instance-0 .send-audio-checkbox")).get(0).click(); user.getDriver().findElement(By.id("session-settings-btn-0")).click(); Thread.sleep(1000);//w ww . ja v a 2 s . c o m WebElement allowedFilterInput = user.getDriver().findElement(By.id("allowed-filter-input")); allowedFilterInput.clear(); allowedFilterInput.sendKeys("ZBarFilter"); user.getDriver().findElement(By.id("add-allowed-filter-btn")).click(); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); // Configure moderator (only subscribe) user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .publish-checkbox")).click(); user.getDriver().findElement(By.id("session-settings-btn-1")).click(); Thread.sleep(1000); user.getDriver().findElement(By.id("radio-btn-mod")).click(); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have only a video track", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), false, true)); // Publisher applies ZBarCode filter to itself user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .filter-btn")).click(); Thread.sleep(500); WebElement input = user.getDriver().findElement(By.id("filter-type-field")); input.clear(); input.sendKeys("ZBarFilter"); input = user.getDriver().findElement(By.id("filter-options-field")); input.clear(); input.sendKeys("{}"); user.getDriver().findElement(By.id("apply-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter applied")); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 2); // Publisher subscribes to CodeFound event for his own stream input = user.getDriver().findElement(By.id("filter-event-type-field")); input.clear(); input.sendKeys("CodeFound"); user.getDriver().findElement(By.id("sub-filter-event-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter event listener added")); user.getEventManager().waitUntilEventReaches("CodeFound", 2); // Publisher unsubscribes from "CodeFound" filter event user.getDriver().findElement(By.id("unsub-filter-event-btn")).click(); try { // If this active wait finishes successfully, then the removal of the event // listener has not worked fine user.getEventManager().waitUntilEventReaches("CodeFound", 3, 3, false); Assert.fail("'filterEvent' was received. Filter.removeEventListener() failed"); } catch (Exception e) { System.out.println("Filter event removal worked fine"); } user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); // Moderator subscribes to CodeFound event for the Publisher's stream user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .filter-btn")).click(); Thread.sleep(500); input = user.getDriver().findElement(By.id("filter-event-type-field")); input.clear(); input.sendKeys("CodeFound"); user.getDriver().findElement(By.id("sub-filter-event-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter event listener added")); user.getEventManager().waitUntilEventReaches("CodeFound", 4); // Moderator removes the Publisher's filter user.getDriver().findElement(By.id("remove-filter-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("filter-response-text-area"), "value", "Filter removed")); user.getEventManager().waitUntilEventReaches("streamPropertyChanged", 4); try { // If this active wait finishes successfully, then the removal of the filter has // not worked fine user.getEventManager().waitUntilEventReaches("CodeFound", 5, 3, false); Assert.fail("'filterEvent' was received. Stream.removeFilter() failed"); } catch (Exception e) { System.out.println("Filter removal worked fine"); } gracefullyLeaveParticipants(2); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("openvidu-java-client test") void openViduJavaClientTest() throws Exception { isRecordingTest = true;//w w w .j a v a 2 s. c om setupBrowser("chromeAlternateScreenShare"); user.getDriver().manage().window().setSize(new Dimension(1000, 800)); log.info("openvidu-java-client test"); user.getDriver().findElement(By.id("one2one-btn")).click(); final String customSessionId = "openviduJavaClientSession"; final String serverDataModerator = "SERVER_DATA_MODERATOR"; final String serverDataSubscriber = "SERVER_DATA_SUBSCRIBER"; final String clientDataModerator = "CLIENT_DATA_MODERATOR"; final String clientDataSubscriber = "CLIENT_DATA_SUBSCRIBER"; Assert.assertFalse("OV.fetch() should return false if OV.createSession() has not been called", OV.fetch()); List<Session> sessions = OV.getActiveSessions(); Assert.assertEquals("Expected no active sessions but found " + sessions.size(), 0, sessions.size()); SessionProperties properties = new SessionProperties.Builder().customSessionId(customSessionId) .mediaMode(MediaMode.ROUTED).recordingMode(RecordingMode.ALWAYS) .defaultOutputMode(OutputMode.INDIVIDUAL).build(); Session session = OV.createSession(properties); Assert.assertFalse("Session.fetch() should return false after OpenVidu.createSession()", session.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false after OpenVidu.createSession()", OV.fetch()); sessions = OV.getActiveSessions(); Assert.assertEquals("Expected 1 active session but found " + sessions.size(), 1, sessions.size()); KurentoOptions kurentoOptions = new KurentoOptions.Builder().videoMaxRecvBandwidth(250) .allowedFilters(new String[] { "GStreamerFilter" }).build(); TokenOptions tokenOptionsModerator = new TokenOptions.Builder().role(OpenViduRole.MODERATOR) .data(serverDataModerator).kurentoOptions(kurentoOptions).build(); String tokenModerator = session.generateToken(tokenOptionsModerator); TokenOptions tokenOptionsSubscriber = new TokenOptions.Builder().role(OpenViduRole.SUBSCRIBER) .data(serverDataSubscriber).build(); String tokenSubscriber = session.generateToken(tokenOptionsSubscriber); Assert.assertFalse("Session.fetch() should return false until a user has connected", session.fetch()); // Set client data 1 WebElement clientDataInput = user.getDriver().findElement(By.cssSelector("#client-data-input-0")); clientDataInput.clear(); clientDataInput.sendKeys(clientDataModerator); // Set token 1 user.getDriver().findElement(By.id("session-settings-btn-0")).click(); Thread.sleep(1000); WebElement tokeInput = user.getDriver().findElement(By.cssSelector("#custom-token-div input")); tokeInput.clear(); tokeInput.sendKeys(tokenModerator); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); // Set client data 2 clientDataInput = user.getDriver().findElement(By.cssSelector("#client-data-input-1")); clientDataInput.clear(); clientDataInput.sendKeys(clientDataSubscriber); // Set token 2 user.getDriver().findElement(By.id("session-settings-btn-1")).click(); Thread.sleep(1000); tokeInput = user.getDriver().findElement(By.cssSelector("#custom-token-div input")); tokeInput.clear(); tokeInput.sendKeys(tokenSubscriber); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); // Moderator sends only video user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .active-audio-checkbox")).click(); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); user.getEventManager().waitUntilEventReaches("recordingStarted", 1); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Moderator video was expected to have audio only track", user.getEventManager().assertMediaTracks( (WebElement) user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 video")), false, true, "#openvidu-instance-0")); Assert.assertTrue("Subscriber video was expected to have audio and video tracks", user.getEventManager().assertMediaTracks( (WebElement) user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 video")), true, true, "#openvidu-instance-1")); Assert.assertTrue("Session.fetch() should return true after users connected", OV.fetch()); Assert.assertFalse("Session.fetch() should return false after OpenVidu.fetch() has been called", session.fetch()); // Verify session properties and status Assert.assertEquals("Wrong sessionId", customSessionId, session.getSessionId()); Assert.assertEquals("Wrong recording mode", RecordingMode.ALWAYS, session.getProperties().recordingMode()); Assert.assertEquals("Wrong default output mode", Recording.OutputMode.INDIVIDUAL, session.getProperties().defaultOutputMode()); Assert.assertTrue("Session should be being recorded", session.isBeingRecorded()); Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections().size(), 2, session.getActiveConnections().size()); Connection connectionModerator; Connection connectionSubscriber; if (OpenViduRole.MODERATOR.equals(session.getActiveConnections().get(0).getRole())) { connectionModerator = session.getActiveConnections().get(0); connectionSubscriber = session.getActiveConnections().get(1); } else { connectionModerator = session.getActiveConnections().get(1); connectionSubscriber = session.getActiveConnections().get(0); } Assert.assertEquals(OpenViduRole.SUBSCRIBER, connectionSubscriber.getRole()); // Verify platform Assert.assertTrue("Wrong platform for moderator connection", connectionModerator.getPlatform().startsWith("Chrome")); Assert.assertTrue("Wrong platform for subscriber connection", connectionSubscriber.getPlatform().startsWith("Chrome")); // Verify publishers Assert.assertEquals( "Expected 1 publisher for connection " + connectionModerator.getConnectionId() + " but found " + connectionModerator.getPublishers().size(), 1, connectionModerator.getPublishers().size()); Assert.assertEquals( "Expected 0 publishers for connection " + connectionSubscriber.getConnectionId() + " but found " + connectionSubscriber.getPublishers().size(), 0, connectionSubscriber.getPublishers().size()); // Verify subscribers Assert.assertEquals( "Expected 0 subscribers for connection " + connectionModerator.getConnectionId() + " but found " + connectionModerator.getSubscribers().size(), 0, connectionModerator.getSubscribers().size()); Assert.assertEquals( "Expected 1 subscriber for connection " + connectionSubscriber.getConnectionId() + " but found " + connectionSubscriber.getSubscribers().size(), 1, connectionSubscriber.getSubscribers().size()); Assert.assertEquals("Publisher and subscriber should have same streamId", connectionModerator.getPublishers().get(0).getStreamId(), connectionSubscriber.getSubscribers().get(0)); // Verify server and client data Assert.assertEquals("Server data doesn't match", serverDataModerator, connectionModerator.getServerData()); Assert.assertEquals("Server data doesn't match", serverDataSubscriber, connectionSubscriber.getServerData()); Assert.assertEquals("Client data doesn't match", clientDataModerator, connectionModerator.getClientData()); Assert.assertEquals("Client data doesn't match", clientDataSubscriber, connectionSubscriber.getClientData()); // Verify publisher properties Publisher pub = connectionModerator.getPublishers().get(0); Assert.assertEquals("{\"width\":640,\"height\":480}", pub.getVideoDimensions()); Assert.assertEquals(new Integer(30), pub.getFrameRate()); Assert.assertEquals("CAMERA", pub.getTypeOfVideo()); Assert.assertTrue(pub.hasVideo()); Assert.assertTrue(pub.isVideoActive()); Assert.assertTrue(pub.hasAudio()); Assert.assertFalse(pub.isAudioActive()); Assert.assertFalse("Session.fetch() should return false", session.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); // Change publisher dynamically user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .change-publisher-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 2); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); Assert.assertTrue("Session.fetch() should return true after publisher changed", session.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false after Session.fetch()", OV.fetch()); // Verify new publisher properties if (OpenViduRole.MODERATOR.equals(session.getActiveConnections().get(0).getRole())) { connectionModerator = session.getActiveConnections().get(0); connectionSubscriber = session.getActiveConnections().get(1); } else { connectionModerator = session.getActiveConnections().get(1); connectionSubscriber = session.getActiveConnections().get(0); } pub = connectionModerator.getPublishers().get(0); String widthAndHeight = user.getEventManager().getDimensionOfViewport(); JSONObject obj = (JSONObject) new JSONParser().parse(widthAndHeight); Assert.assertEquals( "{\"width\":" + (long) obj.get("width") + ",\"height\":" + ((long) obj.get("height")) + "}", pub.getVideoDimensions()); Assert.assertEquals(new Integer(30), pub.getFrameRate()); Assert.assertEquals("SCREEN", pub.getTypeOfVideo()); Assert.assertTrue(pub.hasVideo()); Assert.assertTrue(pub.isVideoActive()); Assert.assertFalse(pub.hasAudio()); Assert.assertNull(pub.isAudioActive()); // Test recording RecordingProperties recordingProperties; try { OV.startRecording("NOT_EXISTS"); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus()); } Session sessionAux = OV.createSession(); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); try { OV.startRecording(sessionAux.getSessionId()); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 406, e.getStatus()); } finally { Assert.assertFalse("Session.fetch() should return false", sessionAux.fetch()); sessionAux.close(); try { sessionAux.fetch(); } catch (OpenViduHttpException e2) { Assert.assertEquals("Wrong HTTP status on Session.fetch()", 404, e2.getStatus()); } Assert.assertFalse("OpenVidu.fetch() should return true", OV.fetch()); } try { recordingProperties = new RecordingProperties.Builder().hasAudio(false).hasVideo(false).build(); OV.startRecording(session.getSessionId(), recordingProperties); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 422, e.getStatus()); } try { recordingProperties = new RecordingProperties.Builder().resolution("99x1080").build(); OV.startRecording(session.getSessionId(), recordingProperties); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 422, e.getStatus()); } try { OV.startRecording(session.getSessionId()); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 409, e.getStatus()); } List<Recording> recordings = OV.listRecordings(); Assert.assertEquals("There should be only 1 recording", 1, recordings.size()); Recording recording = recordings.get(0); Assert.assertEquals("Recording id and name should be equal", recording.getId(), recording.getName()); Assert.assertEquals("Recording id and sessionId should be equal", session.getSessionId(), recording.getId()); // Check ongoing recording properties Assert.assertEquals("Wrong recording session id", session.getSessionId(), recording.getSessionId()); Assert.assertEquals("Wrong recording duration", 0, recording.getDuration(), 0.0001); Assert.assertEquals("Wrong recording size", 0, recording.getSize()); Assert.assertNull("Wrong recording url", recording.getUrl()); Assert.assertEquals("Wrong recording output mode", Recording.OutputMode.INDIVIDUAL, recording.getOutputMode()); Assert.assertNull("Wrong recording layout", recording.getRecordingLayout()); Assert.assertNull("Wrong recording custom layout", recording.getCustomLayout()); Assert.assertNull("Wrong recording resolution", recording.getResolution()); Assert.assertEquals("Wrong recording status", Recording.Status.started, recording.getStatus()); Assert.assertTrue("Wrong recording hasAudio", recording.hasAudio()); Assert.assertTrue("Wrong recording hasVideo", recording.hasVideo()); Thread.sleep(5000); try { OV.stopRecording("NOT_EXISTS"); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus()); } recording = OV.stopRecording(recording.getId()); user.getEventManager().waitUntilEventReaches("recordingStopped", 1); Assert.assertTrue("Wrong recording duration. Expected > 0 and was " + recording.getDuration(), recording.getDuration() > 0); Assert.assertTrue("Wrong recording size. Excepected > 0 and was " + recording.getSize(), recording.getSize() > 0); Assert.assertNotNull("Wrong recording url", recording.getUrl()); Assert.assertEquals("Wrong recording status. Expected ready and was " + recording.getStatus().name(), Recording.Status.ready, recording.getStatus()); Assert.assertFalse("Session shouldn't be being recorded", session.isBeingRecorded()); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); this.checkIndividualRecording("/opt/openvidu/recordings/" + customSessionId + "/", recording, 2, "opus", "vp8", false); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .change-publisher-btn")).click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 3); user.getEventManager().waitUntilEventReaches("streamCreated", 6); user.getEventManager().waitUntilEventReaches("streamPlaying", 6); Assert.assertTrue("Session.fetch() should return true", session.fetch()); final String customRecordingName = "CUSTOM_NAME"; recordingProperties = new RecordingProperties.Builder().outputMode(Recording.OutputMode.COMPOSED) .recordingLayout(RecordingLayout.BEST_FIT).resolution("1280x720").hasVideo(true).hasAudio(false) .name(customRecordingName).build(); Recording recording2 = OV.startRecording(session.getSessionId(), recordingProperties); recording2 = OV.stopRecording(recording2.getId()); Assert.assertEquals("Wrong recording status", Recording.Status.failed, recording2.getStatus()); OV.deleteRecording(recording2.getId()); recording2 = OV.startRecording(session.getSessionId(), recordingProperties); user.getEventManager().waitUntilEventReaches("recordingStarted", 3); Assert.assertEquals("Wrong recording name", customRecordingName, recording2.getName()); Assert.assertEquals("Wrong recording id", session.getSessionId() + "-1", recording2.getId()); Assert.assertEquals("Wrong recording session id", session.getSessionId(), recording2.getSessionId()); Assert.assertEquals("Wrong recording duration", 0, recording2.getDuration(), 0.0001); Assert.assertEquals("Wrong recording size", 0, recording2.getSize()); Assert.assertNull("Wrong recording url", recording2.getUrl()); Assert.assertEquals("Wrong recording output mode", Recording.OutputMode.COMPOSED, recording2.getOutputMode()); Assert.assertEquals("Wrong recording layout", RecordingLayout.BEST_FIT, recording2.getRecordingLayout()); Assert.assertNull("Wrong recording custom layout", recording2.getCustomLayout()); Assert.assertEquals("Wrong recording resolution", "1280x720", recording2.getResolution()); Assert.assertEquals("Wrong recording status", Recording.Status.started, recording2.getStatus()); Assert.assertFalse("Wrong recording hasAudio", recording2.hasAudio()); Assert.assertTrue("Wrong recording hasVideo", recording2.hasVideo()); Thread.sleep(5000); recording2 = OV.stopRecording(recording2.getId()); user.getEventManager().waitUntilEventReaches("recordingStopped", 3); Assert.assertTrue("Wrong recording duration", recording2.getDuration() > 0); Assert.assertTrue("Wrong recording size", recording2.getSize() > 0); Assert.assertNotNull("Wrong recording url", recording2.getUrl()); Assert.assertEquals("Wrong recording status", Recording.Status.ready, recording2.getStatus()); Assert.assertFalse("Session shouldn't be being recorded", session.isBeingRecorded()); Assert.assertFalse("Session.fetch() should return false", session.fetch()); String recordingsPath = "/opt/openvidu/recordings/" + customSessionId + "-1/"; File file1 = new File(recordingsPath + customRecordingName + ".mp4"); File file2 = new File(recordingsPath + ".recording." + recording2.getId()); File file3 = new File(recordingsPath + recording2.getId() + ".jpg"); Assert.assertTrue("File " + file1.getAbsolutePath() + " does not exist or is empty", file1.exists() && file1.length() > 0); Assert.assertTrue("File " + file2.getAbsolutePath() + " does not exist or is empty", file2.exists() && file2.length() > 0); Assert.assertTrue("File " + file3.getAbsolutePath() + " does not exist or is empty", file3.exists() && file3.length() > 0); Assert.assertTrue("Recorded file " + file1.getAbsolutePath() + " is not fine", this.recordedFileFine(file1, recording2)); Assert.assertTrue("Thumbnail " + file3.getAbsolutePath() + " is not fine", this.thumbnailIsFine(file3)); try { OV.deleteRecording("NOT_EXISTS"); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus()); } OV.deleteRecording(recording.getId()); OV.deleteRecording(recording2.getId()); Assert.assertEquals("There shouldn't be any recordings", 0, OV.listRecordings().size()); try { session.forceUnpublish("NOT_EXISTS"); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on Session.fetch()", 404, e.getStatus()); } try { session.forceDisconnect("NOT_EXISTS"); } catch (OpenViduHttpException e) { Assert.assertEquals("Wrong HTTP status on Session.fetch()", 404, e.getStatus()); } if (OpenViduRole.MODERATOR.equals(session.getActiveConnections().get(0).getRole())) { connectionModerator = session.getActiveConnections().get(0); connectionSubscriber = session.getActiveConnections().get(1); } else { connectionModerator = session.getActiveConnections().get(1); connectionSubscriber = session.getActiveConnections().get(0); } pub = connectionModerator.getPublishers().get(0); session.forceUnpublish(pub); user.getEventManager().waitUntilEventReaches("streamDestroyed", 6); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); session.getActiveConnections().forEach(con -> { Assert.assertEquals("Wrong number of Publishers", 0, con.getPublishers().size()); Assert.assertEquals("Wrong number of Subscribers", 0, con.getSubscribers().size()); }); session.forceDisconnect(connectionModerator); user.getEventManager().waitUntilEventReaches("sessionDisconnected", 1); user.getEventManager().waitUntilEventReaches("connectionDestroyed", 1); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); session.close(); user.getEventManager().waitUntilEventReaches("sessionDisconnected", 2); Assert.assertFalse("Session.fetch() should return true", OV.fetch()); gracefullyLeaveParticipants(2); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("REST API test") void restApiTest() throws Exception { isRecordingTest = true;//from ww w . ja va 2s. co m log.info("REST API test"); CustomHttpClient restClient = new CustomHttpClient(OPENVIDU_URL, OPENVIDU_SECRET); // 401 restClient.testAuthorizationError(); /** GET /api/sessions (before session created) **/ restClient.rest(HttpMethod.GET, "/api/sessions/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); Map<String, Object> returnValues = new HashMap<>(); returnValues.put("numberOfElements", new Integer(0)); returnValues.put("content", "[]"); restClient.rest(HttpMethod.GET, "/api/sessions", null, HttpStatus.SC_OK, true, returnValues); /** POST /api/sessions **/ // 400 String body = "{'mediaMode': 'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); body = "{'mediaMode': 'ROUTED', 'recordingMode': false}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); body = "{'mediaMode': 'ROUTED', 'recordingMode': 'ALWAYS', 'customSessionId': 999}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); body = "{'mediaMode': 'ROUTED', 'recordingMode': 'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); body = "{'mediaMode': 'ROUTED', 'recordingMode': 'ALWAYS', 'defaultOutputMode': 'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); body = "{'mediaMode': 'ROUTED', 'recordingMode': 'ALWAYS', 'defaultOutputMode': 'INDIVIDUAL', 'defaultRecordingLayout': 'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_BAD_REQUEST); // 200 body = "{'mediaMode': 'ROUTED', 'recordingMode': 'MANUAL', 'customSessionId': 'CUSTOM_SESSION_ID', 'defaultOutputMode': 'COMPOSED', 'defaultRecordingLayout': 'BEST_FIT'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_OK, true, "{'id': 'STR', 'createdAt': 0}"); // Default values org.json.JSONObject res = restClient.rest(HttpMethod.POST, "/api/sessions", "{}", HttpStatus.SC_OK, true, "{'id': 'STR', 'createdAt': 0}"); restClient.rest(HttpMethod.DELETE, "/api/sessions/" + res.getString("id"), HttpStatus.SC_NO_CONTENT); // 409 body = "{'customSessionId': 'CUSTOM_SESSION_ID'}"; restClient.rest(HttpMethod.POST, "/api/sessions", body, HttpStatus.SC_CONFLICT); /** GET /api/sessions (after session created) **/ restClient.rest(HttpMethod.GET, "/api/sessions/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true, "{'sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':true}"); returnValues = new HashMap<>(); returnValues.put("numberOfElements", new Integer(1)); returnValues.put("content", new org.json.JSONArray()); restClient.rest(HttpMethod.GET, "/api/sessions", null, HttpStatus.SC_OK, true, returnValues); /** POST /api/tokens **/ // 400 body = "{}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': true}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 999}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': false}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'allowedFilters': 'NOT_EXISTS'}}"; restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_BAD_REQUEST); // 200 body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'allowedFilters': ['GStreamerFilter']}}"; res = restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_OK, true, "{'id':'STR','session':'STR','role':'STR','data':'STR','token':'STR','kurentoOptions':{'allowedFilters':['STR']}}"); final String token1 = res.getString("token"); Assert.assertEquals("JSON return value from /api/tokens should have equal srtings in 'id' and 'token'", res.getString("id"), token1); Assert.assertEquals("Wrong session parameter", "CUSTOM_SESSION_ID", res.getString("session")); // Default values body = "{'session': 'CUSTOM_SESSION_ID'}"; res = restClient.rest(HttpMethod.POST, "/api/tokens", body, HttpStatus.SC_OK, true, "{'id':'STR','session':'STR','role':'STR','data':'STR','token':'STR'}"); final String token2 = res.getString("id"); /** POST /api/recordings/start (NOT ACTIVE SESSION) **/ // 400 body = "{}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); body = "{'session': true}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); body = "{'session':'SESSION_ID','name':999}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); body = "{'session':'SESSION_ID','name':'NAME','outputMode':'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); body = "{'session':'SESSION_ID','name':'NAME','outputMode':'COMPOSED','recordingLayout':'NOT_EXISTS'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); body = "{'session':'SESSION_ID','name':'NAME','outputMode':'COMPOSED','recordingLayout':'BEST_FIT','customLayout':'CUSTOM_LAYOUT','hasAudio':true,'hasVideo':true,'resolution':999}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_BAD_REQUEST); // 422 body = "{'session':'SESSION_ID','name':'NAME','outputMode':'COMPOSED','recordingLayout':'BEST_FIT','customLayout':'CUSTOM_LAYOUT','hasAudio':false,'hasVideo':false}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_UNPROCESSABLE_ENTITY); body = "{'session':'SESSION_ID','name':'NAME','outputMode':'COMPOSED','recordingLayout':'BEST_FIT','customLayout':'CUSTOM_LAYOUT','hasAudio':true,'hasVideo':true,'resolution':'1920x2000'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_UNPROCESSABLE_ENTITY); // 404 body = "{'session':'SESSION_ID'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_NOT_FOUND); // 406 body = "{'session':'CUSTOM_SESSION_ID'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_NOT_ACCEPTABLE); // 409 (RELAYED media mode) res = restClient.rest(HttpMethod.POST, "/api/sessions", "{'mediaMode':'RELAYED'}", HttpStatus.SC_OK, true, "{'id': 'STR', 'createdAt': 0}"); body = "{'session':'" + res.getString("id") + "'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_CONFLICT); restClient.rest(HttpMethod.DELETE, "/api/sessions/" + res.getString("id"), HttpStatus.SC_NO_CONTENT); // Start session setupBrowser("chrome"); user.getDriver().findElement(By.id("one2one-btn")).click(); user.getDriver().findElement(By.id("session-settings-btn-0")).click(); Thread.sleep(1000); // Set token 1 WebElement tokeInput = user.getDriver().findElement(By.cssSelector("#custom-token-div input")); tokeInput.clear(); tokeInput.sendKeys(token1); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); user.getDriver().findElement(By.id("session-settings-btn-1")).click(); Thread.sleep(1000); // Set token 2 tokeInput = user.getDriver().findElement(By.cssSelector("#custom-token-div input")); tokeInput.clear(); tokeInput.sendKeys(token2); user.getDriver().findElement(By.id("save-btn")).click(); Thread.sleep(1000); user.getDriver().findElements(By.className("join-btn")).forEach(el -> el.sendKeys(Keys.ENTER)); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 4 videos but found " + numberOfVideos, 4, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); /** GET /api/recordings (before recording started) **/ restClient.rest(HttpMethod.GET, "/api/recordings/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); returnValues = new HashMap<>(); returnValues.put("count", new Integer(0)); returnValues.put("items", "[]"); restClient.rest(HttpMethod.GET, "/api/recordings", null, HttpStatus.SC_OK, true, returnValues); /** POST /api/recordings/start (ACTIVE SESSION) **/ // 200 body = "{'session':'CUSTOM_SESSION_ID'}"; restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_OK, true, "{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':null,'status':'STR'}"); user.getEventManager().waitUntilEventReaches("recordingStarted", 2); Thread.sleep(2000); // 409 (already recording) restClient.rest(HttpMethod.POST, "/api/recordings/start", body, HttpStatus.SC_CONFLICT); /** POST /api/recordings/stop **/ // 405 restClient.rest(HttpMethod.POST, "/api/recordings/stop", body, HttpStatus.SC_METHOD_NOT_ALLOWED); // 404 restClient.rest(HttpMethod.POST, "/api/recordings/stop/NOT_EXISTS", body, HttpStatus.SC_NOT_FOUND); // 200 restClient.rest(HttpMethod.DELETE, "/api/recordings/CUSTOM_SESSION_ID", HttpStatus.SC_CONFLICT); restClient.rest(HttpMethod.POST, "/api/recordings/stop/CUSTOM_SESSION_ID", body, HttpStatus.SC_OK, true, "{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}"); /** GET /api/recordings (after recording created) **/ restClient.rest(HttpMethod.GET, "/api/recordings/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true, "{'id':'STR','sessionId':'STR','name':'STR','outputMode':'STR','recordingLayout':'STR','hasAudio':false,'hasVideo':false,'resolution':'STR','createdAt':0,'size':0,'duration':0,'url':'STR','status':'STR'}"); returnValues = new HashMap<>(); returnValues.put("count", new Integer(1)); returnValues.put("items", new org.json.JSONArray()); restClient.rest(HttpMethod.GET, "/api/recordings", null, HttpStatus.SC_OK, true, returnValues); user.getEventManager().waitUntilEventReaches("recordingStopped", 2); /** DELETE /api/recordings **/ restClient.rest(HttpMethod.DELETE, "/api/recordings", HttpStatus.SC_METHOD_NOT_ALLOWED); restClient.rest(HttpMethod.DELETE, "/api/recordings/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); restClient.rest(HttpMethod.DELETE, "/api/recordings/CUSTOM_SESSION_ID", HttpStatus.SC_NO_CONTENT); // GET /api/recordings should return empty again returnValues = new HashMap<>(); returnValues.put("count", new Integer(0)); returnValues.put("items", "[]"); restClient.rest(HttpMethod.GET, "/api/recordings", null, HttpStatus.SC_OK, true, returnValues); /** DELETE /api/sessions/<SESSION_ID>/stream/<STREAM_ID> **/ restClient.rest(HttpMethod.DELETE, "/api/sessions/NOT_EXISTS/stream/NOT_EXISTS", HttpStatus.SC_BAD_REQUEST); restClient.rest(HttpMethod.DELETE, "/api/sessions/CUSTOM_SESSION_ID/stream/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); res = restClient.rest(HttpMethod.GET, "/api/sessions/CUSTOM_SESSION_ID", null, HttpStatus.SC_OK, true, "{'sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':2,'content'" + ":[{'connectionId':'STR','createdAt':0,'location':'STR','platform':'STR','token':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':[" + "{'createdAt':0,'streamId':'STR','mediaOptions':{'hasAudio':false,'audioActive':false,'hasVideo':false,'videoActive':false,'typeOfVideo':'STR','frameRate':0," + "'videoDimensions':'STR','filter':{}}}],'subscribers':[{'createdAt':0,'streamId':'STR','publisher':'STR'}]},{'connectionId':'STR','createdAt':0,'location':'STR'," + "'platform':'STR','token':'STR','role':'STR','serverData':'STR','clientData':'STR','publishers':[{'createdAt':0,'streamId':'STR','mediaOptions':{'hasAudio':false," + "'audioActive':false,'hasVideo':false,'videoActive':false,'typeOfVideo':'STR','frameRate':0,'videoDimensions':'STR','filter':{}}}],'subscribers':[{'createdAt':0,'streamId':'STR','publisher':'STR'}]}]},'recording':false}"); String streamId = ((org.json.JSONObject) ((org.json.JSONObject) res.getJSONObject("connections") .getJSONArray("content").get(0)).getJSONArray("publishers").get(0)).getString("streamId"); restClient.rest(HttpMethod.DELETE, "/api/sessions/CUSTOM_SESSION_ID/stream/" + streamId, HttpStatus.SC_NO_CONTENT); /** DELETE /api/sessions/<SESSION_ID>/connection/<CONNECTION_ID> **/ restClient.rest(HttpMethod.DELETE, "/api/sessions/NOT_EXISTS/connection/NOT_EXISTS", HttpStatus.SC_BAD_REQUEST); restClient.rest(HttpMethod.DELETE, "/api/sessions/CUSTOM_SESSION_ID/connection/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); String connectionId = ((org.json.JSONObject) res.getJSONObject("connections").getJSONArray("content") .get(0)).getString("connectionId"); restClient.rest(HttpMethod.DELETE, "/api/sessions/CUSTOM_SESSION_ID/connection/" + connectionId, HttpStatus.SC_NO_CONTENT); /** DELETE /api/sessions **/ restClient.rest(HttpMethod.DELETE, "/api/sessions", HttpStatus.SC_METHOD_NOT_ALLOWED); restClient.rest(HttpMethod.DELETE, "/api/sessions/NOT_EXISTS", HttpStatus.SC_NOT_FOUND); restClient.rest(HttpMethod.DELETE, "/api/sessions/CUSTOM_SESSION_ID", HttpStatus.SC_NO_CONTENT); // GET /api/sessions should return empty again returnValues = new HashMap<>(); returnValues.put("numberOfElements", new Integer(0)); returnValues.put("content", "[]"); restClient.rest(HttpMethod.GET, "/api/sessions", null, HttpStatus.SC_OK, true, returnValues); /** GET /config **/ restClient.rest(HttpMethod.GET, "/config", null, HttpStatus.SC_OK, true, "{'version':'STR','openviduPublicurl':'STR','openviduCdr':false,'maxRecvBandwidth':0,'minRecvBandwidth':0,'maxSendBandwidth':0,'minSendBandwidth':0,'openviduRecording':false," + "'openviduRecordingVersion':'STR','openviduRecordingPath':'STR','openviduRecordingPublicAccess':false,'openviduRecordingNotification':'STR'," + "'openviduRecordingCustomLayout':'STR','openviduRecordingAutostopTimeout':0,'openviduWebhook':false,'openviduWebhookEndpoint':'STR','openviduWebhookHeaders':[],'openviduWebhookEvents':[],}"); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("Kurento reconnect test") void kurentoReconnectTest() throws Exception { isRecordingTest = true;/* w w w.ja v a 2s. c om*/ isKurentoRestartTest = true; log.info("Kurento reconnect test"); List<Session> sessions = OV.getActiveSessions(); Assert.assertEquals("Expected no active sessions but found " + sessions.size(), 0, sessions.size()); this.stopKms(); OV.fetch(); setupBrowser("chromeAsRoot"); // Connect one publisher with no connection to KMS user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.className("subscribe-remote-check")).click(); user.getDriver().findElement(By.className("join-btn")).click(); user.getWaiter().until(ExpectedConditions.alertIsPresent()); Alert alert = user.getDriver().switchTo().alert(); final String alertMessage = "Exception connecting to WebSocket server ws://localhost:8888/kurento"; Assert.assertTrue("Alert message wrong. Expected to contain: \"" + alertMessage + "\". Actual message: \"" + alert.getText() + "\"", alert.getText().contains(alertMessage)); alert.accept(); user.getDriver().findElement(By.id("remove-user-btn")).sendKeys(Keys.ENTER); this.startKms(); Thread.sleep(3000); // Connect one subscriber with connection to KMS -> restart KMS -> connect a // publisher -> restart KMS -> check streamDestroyed events user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElements(By.className("publish-checkbox")).forEach(el -> el.click()); user.getDriver().findElement(By.className("join-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 1); OV.fetch(); sessions = OV.getActiveSessions(); Assert.assertEquals("Expected 1 active sessions but found " + sessions.size(), 1, sessions.size()); this.restartKms(); Thread.sleep(3000); OV.fetch(); sessions = OV.getActiveSessions(); Assert.assertEquals("Expected 1 active sessions but found " + sessions.size(), 1, sessions.size()); user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .join-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 1); user.getEventManager().waitUntilEventReaches("streamCreated", 2); user.getEventManager().waitUntilEventReaches("streamPlaying", 2); final int numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 2 videos but found " + numberOfVideos, 2, numberOfVideos); Assert.assertTrue("Videos were expected to have audio and video tracks", user.getEventManager() .assertMediaTracks(user.getDriver().findElements(By.tagName("video")), true, true)); OV.fetch(); Session session = OV.getActiveSessions().get(0); Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2, session.getActiveConnections().size()); int pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum(); int subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum(); Assert.assertEquals("Expected 1 active publisher but found " + pubs, 1, pubs); Assert.assertEquals("Expected 1 active subscriber but found " + subs, 1, subs); OV.startRecording(session.getSessionId(), new RecordingProperties.Builder().outputMode(OutputMode.INDIVIDUAL).build()); user.getEventManager().waitUntilEventReaches("recordingStarted", 2); long recStartTime = System.currentTimeMillis(); final CountDownLatch latch = new CountDownLatch(4); user.getEventManager().on("recordingStopped", (event) -> { String reason = event.get("reason").getAsString(); Assert.assertEquals("Expected 'recordingStopped' reason 'mediaServerDisconnect'", "mediaServerDisconnect", reason); latch.countDown(); }); user.getEventManager().on("streamDestroyed", (event) -> { String reason = event.get("reason").getAsString(); Assert.assertEquals("Expected 'streamDestroyed' reason 'mediaServerDisconnect'", "mediaServerDisconnect", reason); latch.countDown(); }); this.restartKms(); long recEndTime = System.currentTimeMillis(); user.getEventManager().waitUntilEventReaches("recordingStopped", 2); user.getEventManager().waitUntilEventReaches("streamDestroyed", 2); if (!latch.await(5000, TimeUnit.MILLISECONDS)) { gracefullyLeaveParticipants(2); fail("Waiting for 2 streamDestroyed events with reason 'mediaServerDisconnect' to happen in total"); return; } user.getEventManager().off("streamDestroyed"); session.fetch(); Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2, session.getActiveConnections().size()); pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum(); subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum(); Assert.assertEquals("Expected no active publishers but found " + pubs, 0, pubs); Assert.assertEquals("Expected no active subscribers but found " + subs, 0, subs); Recording rec = OV.getRecording("TestSession"); double differenceInDuration = Math.abs(rec.getDuration() - ((recEndTime - recStartTime) / 1000)); Assert.assertTrue("Recording duration exceeds valid value. Expected no more than 0.2 seconds, got " + differenceInDuration, differenceInDuration < 0.2); this.checkIndividualRecording("/opt/openvidu/recordings/TestSession/", rec, 1, "opus", "vp8", true); WebElement pubBtn = user.getDriver().findElements(By.cssSelector("#openvidu-instance-1 .pub-btn")).get(0); pubBtn.click(); user.getEventManager().waitUntilEventReaches("streamDestroyed", 3); // This is not real, only in testapp pubBtn.click(); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); session.fetch(); Assert.assertEquals("Expected 2 active connections but found " + session.getActiveConnections(), 2, session.getActiveConnections().size()); pubs = session.getActiveConnections().stream().mapToInt(con -> con.getPublishers().size()).sum(); subs = session.getActiveConnections().stream().mapToInt(con -> con.getSubscribers().size()).sum(); Assert.assertEquals("Expected 1 active publisher but found " + pubs, 1, pubs); Assert.assertEquals("Expected 1 active subscriber but found " + subs, 1, subs); gracefullyLeaveParticipants(2); }