List of usage examples for org.openqa.selenium.support.ui ExpectedConditions attributeContains
public static ExpectedCondition<Boolean> attributeContains(final By locator, final String attribute, final String value)
From source file:com.fullteaching.backend.e2e.FullTeachingTestE2ESleep.java
License:Apache License
private boolean checkVideoPlaying(BrowserUser user, WebElement videoElement, String containerQuerySelector) { // Video element should be in 'readyState'='HAVE_ENOUGH_DATA' user.getWaiter().until(ExpectedConditions.attributeToBe(videoElement, "readyState", "4")); // Video should have a srcObject (type MediaStream) with the attribute 'active' to true Assert.assertTrue((boolean) user.runJavascript("return document.querySelector('" + containerQuerySelector + "').getElementsByTagName('video')[0].srcObject.active")); // Video should trigger 'playing' event user.runJavascript("document.querySelector('" + containerQuerySelector + "').getElementsByTagName('video')[0].addEventListener('playing', window.MY_FUNC('" + containerQuerySelector + "'));"); user.getWaiter().until(//from w w w . ja va2 s .co m ExpectedConditions.attributeContains(By.id("video-playing-div"), "innerHTML", "VIDEO PLAYING")); user.runJavascript("document.body.removeChild(document.getElementById('video-playing-div'))"); return true; }
From source file:com.liferay.faces.bridge.test.integration.issue.FACES_257PortletTester.java
License:Open Source License
private static void assertURLEndsWith(BrowserDriver browserDriver, WaitingAsserter waitingAsserter, String linkXpath, String expectedURLEnding) { waitingAsserter/*from www. ja va 2 s. co m*/ .assertTrue(ExpectedConditions.attributeContains(By.xpath(linkXpath), "href", expectedURLEnding)); Assert.assertTrue(browserDriver.getCurrentWindowUrl().endsWith(expectedURLEnding)); }
From source file:com.liferay.faces.portal.test.integration.demo.PrimeFacesUsersPortletTester.java
License:Open Source License
private ExpectedCondition<Boolean> textPresentInElementClass(String text, String elementXpath) { By locator = By.xpath(elementXpath); ExpectedCondition<WebElement> elementDisplayed = ExpectedConditions.visibilityOfElementLocated(locator); ExpectedCondition<Boolean> textPresentInElementClass = ExpectedConditions.attributeContains(locator, "class", text); return ExpectedConditions.and(elementDisplayed, textPresentInElementClass); }
From source file:com.liferay.faces.test.alloy.showcase.datatable.DataTableTesterBase.java
License:Open Source License
/** * Determines whether or not the specified text is present in the class attribute of the element targeted by the * specified xpath expression.//from w w w. j av a 2s . co m */ private ExpectedCondition<Boolean> isTextPresentInElementClassAttribute(String text, String elementXpath) { By locator = By.xpath(elementXpath); ExpectedCondition<WebElement> elementDisplayed = ExpectedConditions.visibilityOfElementLocated(locator); ExpectedCondition<Boolean> textPresentInElementClass = ExpectedConditions.attributeContains(locator, "class", text); return ExpectedConditions.and(elementDisplayed, textPresentInElementClass); }
From source file:io.federecio.dropwizard.swagger.selenium.DefaultServerWithCustomTemplateSeleniumTest.java
License:Apache License
@Test public void testCustomLogo() throws Exception { driver.get(getSwaggerUrl());/*from w w w. j ava 2 s.co m*/ driver.manage().timeouts().implicitlyWait(WAIT_IN_SECONDS, TimeUnit.SECONDS); // Check for custom logo in the template By inputSelector = By.xpath("//img[@class=\"logo__img\"]"); new WebDriverWait(driver, WAIT_IN_SECONDS) .until(ExpectedConditions.presenceOfElementLocated(inputSelector)); new WebDriverWait(driver, WAIT_IN_SECONDS) .until(ExpectedConditions.attributeContains(inputSelector, "src", "myassets/dropwizard-logo.png")); }
From source file:io.openvidu.test.e2e.OpenViduTestAppE2eTest.java
License:Apache License
@Test @DisplayName("REST API: Fetch all, fetch one, force disconnect, force unpublish, close session") void restApiFetchForce() throws Exception { setupBrowser("chrome"); log.info("REST API: Fetch all, fetch one, force disconnect, force unpublish, close session"); user.getDriver().findElement(By.id("add-user-btn")).click(); user.getDriver().findElement(By.id("add-user-btn")).click(); // API REST test user.getDriver().findElement(By.id("session-api-btn-0")).click(); Thread.sleep(1000);/*from www .j av a 2 s . c om*/ // Close session (undefined) user.getDriver().findElement(By.id("close-session-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [Session undefined]")); // Fetch one (undefined) user.getDriver().findElement(By.id("get-session-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [Session undefined]")); // Fetch all (no active sessions) user.getDriver().findElement(By.id("list-sessions-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value", "Number: 0. Changes: false")); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(1000); user.getDriver().findElement(By.id("auto-join-checkbox")).click(); user.getDriver().findElement(By.id("one2one-btn")).click(); user.getEventManager().waitUntilEventReaches("connectionCreated", 4); user.getEventManager().waitUntilEventReaches("accessAllowed", 2); user.getEventManager().waitUntilEventReaches("streamCreated", 4); user.getEventManager().waitUntilEventReaches("streamPlaying", 4); 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)); // Fetch existing session (change) user.getDriver().findElement(By.id("session-api-btn-0")).click(); Thread.sleep(1000); user.getDriver().findElement(By.id("get-session-btn")).click(); Thread.sleep(1000); System.out.println(getBase64Screenshot(user)); System.out.println(user.getDriver().findElement(By.id("api-response-text-area")).getAttribute("value")); user.getWaiter().until( ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value", "Changes: true")); // Store connectionId and streamId String response = user.getDriver().findElement(By.id("api-response-text-area")).getAttribute("value"); JSONObject json = (JSONObject) ((JSONArray) new JSONParser().parse(response.split("%")[1])).get(0); String connectionId = (String) json.keySet().iterator().next(); String streamId = (String) ((JSONObject) ((JSONArray) json.get(connectionId)).get(0)).get("streamId"); // Fetch all sessions (no change) user.getDriver().findElement(By.id("list-sessions-btn")).click(); user.getWaiter().until(ExpectedConditions.attributeContains(By.id("api-response-text-area"), "value", "Number: 1. Changes: false")); // Force unpublish wrong user.getDriver().findElement(By.id("resource-id-field")).clear(); user.getDriver().findElement(By.id("resource-id-field")).sendKeys("FAIL"); user.getDriver().findElement(By.id("force-unpublish-api-btn")).click(); user.getWaiter() .until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [404]")); // Force unpublish right user.getDriver().findElement(By.id("resource-id-field")).clear(); user.getDriver().findElement(By.id("resource-id-field")).sendKeys(streamId); user.getDriver().findElement(By.id("force-unpublish-api-btn")).click(); user.getWaiter().until( ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Stream unpublished")); user.getEventManager().waitUntilEventReaches("streamDestroyed", 2); numberOfVideos = user.getDriver().findElements(By.tagName("video")).size(); Assert.assertEquals("Expected 3 videos but found " + numberOfVideos, 3, numberOfVideos); // Force disconnect wrong user.getDriver().findElement(By.id("resource-id-field")).clear(); user.getDriver().findElement(By.id("resource-id-field")).sendKeys("FAIL"); user.getDriver().findElement(By.id("force-disconnect-api-btn")).click(); user.getWaiter() .until(ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Error [404]")); // Force disconnect right user.getDriver().findElement(By.id("resource-id-field")).clear(); user.getDriver().findElement(By.id("resource-id-field")).sendKeys(connectionId); user.getDriver().findElement(By.id("force-disconnect-api-btn")).click(); user.getWaiter().until( ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "User disconnected")); user.getEventManager().waitUntilEventReaches("connectionDestroyed", 1); // Close session user.getDriver().findElement(By.id("close-session-btn")).click(); user.getWaiter().until( ExpectedConditions.attributeToBe(By.id("api-response-text-area"), "value", "Session closed")); user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.tagName("video"), 0)); user.getDriver().findElement(By.id("close-dialog-btn")).click(); Thread.sleep(500); gracefullyLeaveParticipants(1); }
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);/*from www . j a v a2 s. c o 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);//from w w w . j a v a 2 s. c om 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:org.keycloak.testsuite.page.AbstractPatternFlyAlert.java
License:Apache License
protected boolean checkAlertType(String type) { try {/*from w w w . j av a 2s.c o m*/ new WebDriverWait(driver, 1) .until(ExpectedConditions.attributeContains(alertRoot, "class", "alert-" + type)); } catch (TimeoutException e) { return false; } return true; }