Quick Start (Surfmeter Selenium for Java)¶
Everything installed? Let's build our first video test!
import org.openqa.selenium.By;
import com.aveq.selenium.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
class MyTest {
protected WebDriver driver;
protected SurfmeterVideoTest surfmeter;
@BeforeEach
public void setup() {
driver = new ChromeDriver(); // create your driver here!
surfmeter = SurfmeterVideoTest.Builder()
.driver(driver)
.endpoint("YOUR_ENDPOINT") // relevant for on-promise solutions, otherwise the AVEQ demo-server will be used - endpoint: where we check your license AND where you can get more data insights in our dashboards
.apiKey("YOUR_API_KEY")
.jsPath("PATH_TO_SURFMETER_AUTO_SDK.JS")
// .options(...) // you can define further options, we will discuss later in this README
.build();
}
@Test
public void test() {
// navigate to your test page
driver.get("https://example.com/video-page");
// fetch video from page
WebElement video = driver.findElement(By.cssSelector("video"));
// ... // you may want to do further interaction here (like, e.g. clicking a play btn)
// fetch statistics as soon as they are available
surfmeter.getMonitoredVideo(video).fetchQualityStatistics();
}
@AfterEach
public void teardown() {
// stop surfmeter
surfmeter.stop();
// quit your driver
driver.quit();
}
}
TheĀ above example uses the SurfmeterVideoTest
class as a tool to automatically inject the Surfmeter Auto SDK JavaScript file whenever a new URL is called. This is done by using an UrlMonitor
(cf. src/main/java/com/aveq/util/UrlMonitor.java
), which fires a callback whenever a URL changes in the page.
This approach is recommended, especially for pages like YouTube which perform internal forwarding during a browser session, e.g. when you accept/decline cookies.
Of course you may measure simpler sites which do not reload themselves. In such cases, a usual script injection should be sufficient. As the Surfmeter Selenium for Java library is distributed as open-source code, you can directly review the SurfmeterVideoTest#injectSurfmeterJavascriptLibrary
(cf. src/main/java/com/aveq/selenium/SurfmeterVideoTest.java
)-method for this.
Note
For precise video test results, we recommend to set the page load preference to PageLoadStrategy.NONE
. While it is not required to do so, to run the Auto SDK at all, we recommend it, as for some pages videos cannot measured properly. Read more on that in our Best Practices section.