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));
}
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")));
}
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());
}
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);
}
};
}
Aggregations