|
| 1 | +package org.openqa.selenium.qtwebkit; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertFalse; |
| 4 | +import static org.junit.Assert.assertNotEquals; |
| 5 | +import static org.junit.Assert.assertTrue; |
| 6 | +import com.google.common.collect.Iterables; |
| 7 | + |
| 8 | +import org.junit.After; |
| 9 | +import org.junit.Before; |
| 10 | +import org.junit.BeforeClass; |
| 11 | +import org.junit.Test; |
| 12 | +import org.openqa.selenium.logging.LogEntries; |
| 13 | +import org.openqa.selenium.logging.LogEntry; |
| 14 | +import org.openqa.selenium.logging.LogType; |
| 15 | +import org.openqa.selenium.logging.LoggingPreferences; |
| 16 | +import org.openqa.selenium.remote.CapabilityType; |
| 17 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 18 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 19 | +import org.openqa.selenium.testing.JUnit4TestBase; |
| 20 | +import java.util.Set; |
| 21 | +import java.util.logging.Level; |
| 22 | + |
| 23 | + |
| 24 | +public class PerfLoggingTest extends JUnit4TestBase { |
| 25 | + |
| 26 | + @Before |
| 27 | + public void createDriver() { |
| 28 | + } |
| 29 | + |
| 30 | + @After |
| 31 | + public void cleanUp() { |
| 32 | + if (null == driver) { |
| 33 | + return; |
| 34 | + } |
| 35 | + driver.quit(); |
| 36 | + driver = null; |
| 37 | + } |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void cleanUpExistingDriver() { |
| 41 | + JUnit4TestBase.removeDriver(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void performanceLogShouldBeDisabledByDefault() { |
| 46 | + driver = actuallyCreateDriver(); |
| 47 | + Set<String> logTypes = driver.manage().logs().getAvailableLogTypes(); |
| 48 | + assertFalse("Performance log should not be enabled by default", |
| 49 | + logTypes.contains(LogType.PERFORMANCE)); |
| 50 | + JUnit4TestBase.removeDriver(); |
| 51 | + } |
| 52 | + |
| 53 | + private void createDriverWithPerformanceLogType() { |
| 54 | + DesiredCapabilities caps = DesiredCapabilities.qtwebkit(); |
| 55 | + LoggingPreferences logPrefs = new LoggingPreferences(); |
| 56 | + logPrefs.enable(LogType.PERFORMANCE, Level.INFO); |
| 57 | + caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); |
| 58 | + QtWebDriverExecutor executor = QtWebKitDriver.createDefaultExecutor(); |
| 59 | + driver = new RemoteWebDriver(executor, caps); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void shouldBeAbleToEnablePerformanceLog() { |
| 64 | + createDriverWithPerformanceLogType(); |
| 65 | + Set<String> logTypes = driver.manage().logs().getAvailableLogTypes(); |
| 66 | + assertTrue("Profiler log should be enabled", logTypes.contains(LogType.PERFORMANCE)); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void pageLoadShouldProducePerformanceLogEntries() { |
| 71 | + createDriverWithPerformanceLogType(); |
| 72 | + driver.get(pages.simpleTestPage); |
| 73 | + LogEntries entries = driver.manage().logs().get(LogType.PERFORMANCE); |
| 74 | + assertNotEquals(0, Iterables.size(entries)); |
| 75 | + } |
| 76 | + |
| 77 | + |
| 78 | + @Test |
| 79 | + public void performanceLogEntriesShouldHaveNeededStructure() { |
| 80 | + createDriverWithPerformanceLogType(); |
| 81 | + driver.get(pages.simpleTestPage); |
| 82 | + LogEntries entries = driver.manage().logs().get(LogType.PERFORMANCE); |
| 83 | + for(LogEntry e : entries.getAll()) { |
| 84 | + assertTrue(e.getMessage().contains("webview")); |
| 85 | + assertTrue(e.getMessage().contains("message")); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments