Search in sources :

Example 1 with Har

use of net.lightbody.bmp.core.har.Har in project sdc by onap.

the class SetupCDTest method addTrafficFileToReport.

private void addTrafficFileToReport(ITestResult result) {
    try {
        // Get the HAR data
        Har har = MobProxy.getPoxyServer().getHar();
        String shortUUID = UUID.randomUUID().toString().split("-")[0];
        File harFile = new File(getHarFilesFolder() + result.getName() + shortUUID + ".har");
        new File(getHarFilesFolder()).mkdirs();
        har.writeTo(harFile);
        String pathToFileFromReportDirectory = HAR_FILES_FOLDER_NAME + File.separator + harFile.getName();
        ExtentTestActions.addFileToReportAsLink(harFile, pathToFileFromReportDirectory, "File with captured traffic");
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
Also used : Har(net.lightbody.bmp.core.har.Har) IOException(java.io.IOException) UserCredentialsFromFile(org.onap.sdc.backend.ci.tests.config.UserCredentialsFromFile) File(java.io.File)

Example 2 with Har

use of net.lightbody.bmp.core.har.Har in project staf by simpleworks-gmbh.

the class APITestCase method createArtefact.

@Override
public HarFile createArtefact() {
    final BrowserMobProxyServer proxy = client.getBrowserMobProxyServer();
    if (proxy == null) {
        return null;
    }
    HarFile result = null;
    try {
        final Har har = proxy.getHar();
        if (har != null) {
            final File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".har");
            if (APITestCase.logger.isDebugEnabled()) {
                APITestCase.logger.debug(String.format("write HAR into file: '%s'.", tempFile));
            }
            tempFile.deleteOnExit();
            har.writeTo(tempFile);
            result = new HarFile(tempFile);
        }
    } catch (final Exception ex) {
        APITestCase.logger.error("can't create artifact.", ex);
    }
    return result;
}
Also used : Har(net.lightbody.bmp.core.har.Har) HarFile(de.simpleworks.staf.commons.report.artefact.HarFile) HarFile(de.simpleworks.staf.commons.report.artefact.HarFile) File(java.io.File) BrowserMobProxyServer(net.lightbody.bmp.BrowserMobProxyServer) SystemException(de.simpleworks.staf.commons.exceptions.SystemException)

Example 3 with Har

use of net.lightbody.bmp.core.har.Har in project selenium-webdriver-java by bonigarcia.

the class HarCreatorJupiterTest method teardown.

@AfterEach
void teardown() throws IOException {
    Har har = proxy.getHar();
    File harFile = new File("login.har");
    har.writeTo(harFile);
    proxy.stop();
    driver.quit();
}
Also used : Har(net.lightbody.bmp.core.har.Har) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach)

Example 4 with Har

use of net.lightbody.bmp.core.har.Har in project selenium-webdriver-java by bonigarcia.

the class HarCreatorSelJupTest method teardown.

@AfterEach
void teardown() throws IOException {
    Har har = proxy.getHar();
    File harFile = new File("login.har");
    har.writeTo(harFile);
    proxy.stop();
}
Also used : Har(net.lightbody.bmp.core.har.Har) File(java.io.File) AfterEach(org.junit.jupiter.api.AfterEach)

Example 5 with Har

use of net.lightbody.bmp.core.har.Har in project selenium-tests by Wikia.

the class Log method stop.

public static void stop() {
    WikiaWebDriver driver = DriverProvider.getActiveDriver();
    if (driver.getProxy() != null && Configuration.getForceHttps()) {
        Har har = driver.getProxy().getHar();
        for (HarEntry entry : har.getLog().getEntries()) {
            URL url;
            try {
                url = new URL(entry.getRequest().getUrl());
                if (url.getHost().contains("wikia")) {
                    boolean isHttps = entry.getRequest().getUrl().startsWith("https");
                    Log.log("VISITED URL", "Url: " + entry.getRequest().getUrl(), !Configuration.getForceHttps() || isHttps);
                }
            } catch (MalformedURLException e) {
                Log.log("MALFORMED URL", "Url: " + entry.getRequest().getUrl(), false);
            }
        }
    }
    if (driver.getProxy() != null && Configuration.getAdsData()) {
        Har har = driver.getProxy().getHar();
        for (HarEntry entry : har.getLog().getEntries()) {
            try {
                if (entry.getRequest().getUrl().contains("adeng")) {
                    String[] urlValue = entry.getRequest().getUrl().split("(adeng).+\\?");
                    String[] values = urlValue[1].split("&");
                    Log.info("Ad parameters", "Header: " + Arrays.toString(values));
                }
            } catch (NullPointerException ex) {
                Log.info("Did not get successful response", ex);
            }
        }
        Pattern pt = Pattern.compile("\\d{2,}");
        WebElement mercuryScriptVersion = null;
        if (Configuration.getEmulator().isMobile()) {
            mercuryScriptVersion = driver.findElement(By.cssSelector("script[src*='mercury_ads_js']"));
        }
        String mercuryAdsJsValue = mercuryScriptVersion.getAttribute("src");
        Matcher matcher = pt.matcher(mercuryAdsJsValue);
        if (matcher.find()) {
            mercuryAdsJsValue = matcher.group(0);
        } else {
            throw new WebDriverException("Missing mobile param in query string");
        }
        Log.info("Mercury Ads Version: " + mercuryAdsJsValue);
    }
    if (Configuration.getMobileWikiVersion() != null) {
        Log.info("Mobile Wiki Version: " + Configuration.getMobileWikiVersion());
    }
    String html = VelocityWrapper.fillLastLogRow();
    CommonUtils.appendTextToFile(Log.LOG_PATH, html);
    Log.testStarted = false;
}
Also used : HarEntry(net.lightbody.bmp.core.har.HarEntry) Pattern(java.util.regex.Pattern) MalformedURLException(java.net.MalformedURLException) Matcher(java.util.regex.Matcher) URL(java.net.URL) WikiaWebDriver(com.wikia.webdriver.common.core.WikiaWebDriver) Har(net.lightbody.bmp.core.har.Har)

Aggregations

Har (net.lightbody.bmp.core.har.Har)20 File (java.io.File)10 HarLog (net.lightbody.bmp.core.har.HarLog)9 GenericTest (com.seleniumtests.GenericTest)8 TestStep (com.seleniumtests.reporter.logger.TestStep)8 HarPage (net.lightbody.bmp.core.har.HarPage)8 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)6 HarCapture (com.seleniumtests.reporter.logger.HarCapture)5 IOException (java.io.IOException)3 GenericFile (com.seleniumtests.reporter.logger.GenericFile)2 TestAction (com.seleniumtests.reporter.logger.TestAction)2 TestMessage (com.seleniumtests.reporter.logger.TestMessage)2 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 BrowserMobProxyServer (net.lightbody.bmp.BrowserMobProxyServer)2 HarEntry (net.lightbody.bmp.core.har.HarEntry)2 AfterEach (org.junit.jupiter.api.AfterEach)2 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1