Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage via proxy on PhantomJS (Selenium automation). #220

Closed
jwaliszko opened this issue Dec 30, 2015 · 4 comments
Closed

Coverage via proxy on PhantomJS (Selenium automation). #220

jwaliszko opened this issue Dec 30, 2015 · 4 comments
Assignees
Labels

Comments

@jwaliszko
Copy link

I'd like to collect code coverage statistics during few coded UI tests execution.

I'm working with JSCover 1.0.23-SNAPSHOT, XUnit 2.1.0, Selenium.WebDriver 2.48.2, PhantomJS 2.0.0 and basic ASP.NET MVC 4 application hosted in IISExpress 10 on Win7 machine.

  • When using JSCover through proxy on Firefox, everything works as expected:

    Start JSCover with proxy args:

    >java -jar JSCover-all.jar -ws --proxy --port=3128 --report-dir=reports --local-storage
    

    Setup WebDriver in C#:

    using OpenQA.Selenium;
    using OpenQA.Selenium.Firefox;
    using OpenQA.Selenium.Remote;
    
    var proxy = new Proxy {HttpProxy = "localhost:3128"};
    var capabilities = new DesiredCapabilities();
    capabilities.SetCapability(CapabilityType.Proxy, proxy);
    Driver = new FirefoxDriver(capabilities);
    

    Invoke few tests:

    Driver.Navigate().GoToUrl("http://localhost:51622/"); // site hosted on IISExpress
    Driver.FindElementByXPath(...).Click(); // etc.
    

    Expect results to be generated (awesome!):

    image

  • When using JSCover through proxy on PhantomJS instead, unfortunately either it doesn't work, or I'm doing something incorrectly:

    Start JSCover with proxy args (same as before):

    >java -jar JSCover-all.jar -ws --proxy --port=3128 --report-dir=reports --local-storage
    

    Start PhantomJS:

    >phantomjs --proxy=localhost:3128 --proxy-type=http --webdriver=4444
    

    Setup WebDriver in C#:

    using OpenQA.Selenium;
    using OpenQA.Selenium.PhantomJS;
    using OpenQA.Selenium.Remote;
    
    var proxy = new Proxy {HttpProxy = "localhost:3128"};
    var capabilities = DesiredCapabilities.PhantomJS();
    capabilities.SetCapability(CapabilityType.Proxy, proxy);            
    Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
    

    Invoke few tests (same as before):

    Driver.Navigate().GoToUrl("http://localhost:51622/"); // site hosted on IISExpress
    Driver.FindElementByXPath(...).Click(); // etc.
    

    Expect unavailable results (checking in Firefox browser, by pasting expected results URL manually):

    image 1

    Supplementary logs:

    image

    image

Is it possible to configure coverage that or similar way?

I'm interested in proxy version in particular, I haven't tried explicit instrumentation.
Also I'm not sure if this is a problem related to JSCover, or maybe some other component used here.

Regards

@tntim96 tntim96 self-assigned this Jan 3, 2016
@tntim96
Copy link
Owner

tntim96 commented Jan 3, 2016

JSCover can collect coverage when run as a proxy, but it is preferable to instrument the JavaScript first and not use the proxy mode unless pre-instrumenting is not possible.

This approach should work fine (I've used PhantomJS too via Ghostdriver)

I'm guessing in your second version of FireFox, the 404 is occurring because you haven't manually configured the proxy in the browser.

Can you just replace new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities); with new PhantomJSDriver() as done here?

@jwaliszko
Copy link
Author

Indeed I've missed the manual proxy configuration for Firefox.
After appropriate setup, I'm able to retrieve the report page, but without any coverage statistics:

image

I've tried also alternative C# configurations, e.g.

var service = PhantomJSDriverService.CreateDefaultService();
service.AddArgument("--proxy=localhost:3128");
Driver = new PhantomJSDriver(service);

or

var options = new PhantomJSOptions();
options.AddAdditionalCapability(CapabilityType.Proxy, new Dictionary<string, string>
{
    {"proxyType", "MANUAL"},
    {"httpProxy", "localhost:3128"}
});            

var service = PhantomJSDriverService.CreateDefaultService();
service.ProxyType = "http";
service.Proxy = "localhost:3128";
service.IgnoreSslErrors = true;
service.WebSecurity = false;

Driver = new PhantomJSDriver(service, options, TimeSpan.FromSeconds(10.0));
Driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));

Still no results.

To avoid confusion with Firefox verifications, what I've alternatively tried is to navigate to the results page using the driver itself:

Driver.Navigate().GoToUrl("http://localhost:51622/jscoverage.html");

but got 404:

image

image

There are reports related to localhost proxy, e.g. ariya/phantomjs#11342 or ariya/phantomjs#12703. Nevertheless despite adding 127.0.0.1 local-proxy entry to C:\Windows\System32\drivers\etc\hosts file, and configuring PhantomJS using local-proxy:3128 instead of localhost:3128, 404 issue is constantly there.

There is more confusion with the proxy setup for PhantomJS as seen e.g. in ariya/phantomjs#12420 or ariya/phantomjs#11619 so I'm not sure where the problem actually is.

@tntim96
Copy link
Owner

tntim96 commented Jan 3, 2016

It looks like a PhantomJS proxy issue - that last test you did seems to confirm it.

@jwaliszko
Copy link
Author

Thanks for your time.
Maybe someone from PhantomJS (@ariya, @vitallium, @zackw) or possibly Selenium (@jimevans) would like to consider a closer look at this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants