Search in sources :

Example 1 with InstanceFieldPerPropertyConfig

use of com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig in project saga by timurstrekalov.

the class DefaultCoverageGeneratorIT method test_instrumentAndGenerateReports_with_phantomjs.

@Test
@Ignore
public void test_instrumentAndGenerateReports_with_phantomjs() throws Exception {
    final FileServer fileServer = new FileServer(getClass().getResource("/tests").toURI().toASCIIString());
    final int fileServerPort = fileServer.start();
    config = new InstanceFieldPerPropertyConfig();
    // localhost/127.0.0.1 don't work - requests never hit the proxy, and there's no way to tell phantomjs to proxy local requests
    config.setBaseDir("http://192.168.1.100:" + fileServerPort + "/ClassTest.html");
    config.setOutputDir(new File(Data.getProperty("build.directory") + "/coverage-phantomjs"));
    config.setBackgroundJavaScriptTimeout(2000L);
    generator = new DefaultCoverageGenerator(config);
    config.setWebDriverClassName("org.openqa.selenium.phantomjs.PhantomJSDriver");
    config.setWebDriverCapabilities(ImmutableMap.of("phantomjs.binary.path", "/opt/boxen/homebrew/bin/phantomjs"));
    generator.instrumentAndGenerateReports();
    assertThat(config.getOutputDir().list().length, is(greaterThanOrEqualTo(2)));
    final File html = new File(config.getOutputDir(), "total-report.html");
    final String htmlAsString = Files.toString(html, Charset.forName("UTF-8"));
    final Matcher m = EXECUTED_STATEMENTS_PATTERN.matcher(htmlAsString);
    assertThat(m.find(), is(true));
    assertThat(Integer.parseInt(m.group(1)), greaterThanOrEqualTo(85));
    assertThat(html.exists(), is(true));
    assertThat(new File(config.getOutputDir(), "total-coverage.dat").exists(), is(true));
}
Also used : Matcher(java.util.regex.Matcher) InstanceFieldPerPropertyConfig(com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with InstanceFieldPerPropertyConfig

use of com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig in project saga by timurstrekalov.

the class DefaultCoverageGeneratorIT method test_instrumentAndGenerateReports.

@Test
public void test_instrumentAndGenerateReports() throws Exception {
    config = new InstanceFieldPerPropertyConfig();
    config.setBaseDir(getClass().getResource("/tests").toURI().toASCIIString());
    config.setOutputDir(new File(Data.getProperty("build.directory") + "/coverage-htmlunit"));
    config.setIncludes("**/*Test*.html");
    config.setBackgroundJavaScriptTimeout(5000L);
    generator = new DefaultCoverageGenerator(config);
    generator.instrumentAndGenerateReports();
    assertThat(config.getOutputDir().list().length, is(greaterThan(0)));
    final File html = new File(config.getOutputDir(), "total-report.html");
    final String htmlAsString = Files.toString(html, Charset.forName("UTF-8"));
    final Matcher m = EXECUTED_STATEMENTS_PATTERN.matcher(htmlAsString);
    assertThat(m.find(), is(true));
    assertThat(Integer.parseInt(m.group(1)), greaterThanOrEqualTo(85));
    assertThat(html.exists(), is(true));
    final File lcov = new File(config.getOutputDir(), "total-coverage.dat");
    assertThat(lcov.exists(), is(true));
    final List<String> lcovLines = CharStreams.readLines(new InputSupplier<FileReader>() {

        @Override
        public FileReader getInput() throws IOException {
            return new FileReader(lcov);
        }
    });
    assertThat(lcovLines.get(0), is(equalTo("SF:ClassTest.js")));
    assertThat(lcovLines.get(4), is(equalTo("SF:pkg/ClassTest2.js")));
}
Also used : Matcher(java.util.regex.Matcher) FileReader(java.io.FileReader) IOException(java.io.IOException) InstanceFieldPerPropertyConfig(com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig) File(java.io.File) Test(org.junit.Test)

Example 3 with InstanceFieldPerPropertyConfig

use of com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig in project saga by timurstrekalov.

the class HtmlUnitBasedScriptInstrumenterTest method verifyClassJsData.

private void verifyClassJsData(String sourceName, String expectedSourceName) {
    final ScriptInstrumenter instrumenter = new HtmlUnitBasedScriptInstrumenter(new InstanceFieldPerPropertyConfig());
    instrumenter.instrument(Data.getClassJsSourceCode(), sourceName, 1);
    assertEquals(1, instrumenter.getScriptDataList().size());
    final ScriptData classJsData = instrumenter.getScriptDataList().get(0);
    assertEquals(expectedSourceName, classJsData.getSourceUriAsString());
    assertEquals(5, classJsData.getLineNumberOfFirstStatement());
    assertEquals(114, classJsData.getNumberOfStatements());
    assertEqualsIgnoreCRLF(Data.getClassJsInstrumented(expectedSourceName), classJsData.getInstrumentedSourceCode());
}
Also used : ScriptData(com.github.timurstrekalov.saga.core.model.ScriptData) InstanceFieldPerPropertyConfig(com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig)

Example 4 with InstanceFieldPerPropertyConfig

use of com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig in project saga by timurstrekalov.

the class InstrumentingProxyServerIT method setUp.

@Before
public void setUp() throws Exception {
    final InstanceFieldPerPropertyConfig config = new InstanceFieldPerPropertyConfig();
    proxyServer = new InstrumentingProxyServer(new HtmlUnitBasedScriptInstrumenter(config));
    fileServer = new FileServer(new File(getClass().getResource("/tests").toURI()).getAbsolutePath());
    proxyServerPort = proxyServer.start();
    fileServerPort = fileServer.start();
    final String proxyUrl = "localhost:" + proxyServerPort;
    final Proxy proxy = new Proxy().setProxyType(Proxy.ProxyType.MANUAL).setHttpProxy(proxyUrl).setSslProxy(proxyUrl);
    final DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
    desiredCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
    desiredCapabilities.setBrowserName(BrowserType.FIREFOX);
    driver = new HtmlUnitDriver(desiredCapabilities) {

        @Override
        protected WebClient newWebClient(final BrowserVersion version) {
            config.setBrowserVersion(version);
            return WebClientFactory.newInstance(config);
        }
    };
}
Also used : Proxy(org.openqa.selenium.Proxy) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) InstanceFieldPerPropertyConfig(com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig) InstrumentingProxyServer(com.github.timurstrekalov.saga.core.server.InstrumentingProxyServer) File(java.io.File) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) WebClient(com.gargoylesoftware.htmlunit.WebClient) FileServer(com.github.timurstrekalov.saga.core.FileServer) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Before(org.junit.Before)

Aggregations

InstanceFieldPerPropertyConfig (com.github.timurstrekalov.saga.core.cfg.InstanceFieldPerPropertyConfig)4 File (java.io.File)3 Matcher (java.util.regex.Matcher)2 Test (org.junit.Test)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 FileServer (com.github.timurstrekalov.saga.core.FileServer)1 ScriptData (com.github.timurstrekalov.saga.core.model.ScriptData)1 InstrumentingProxyServer (com.github.timurstrekalov.saga.core.server.InstrumentingProxyServer)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Proxy (org.openqa.selenium.Proxy)1 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)1 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)1