Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Unable to write to html report #67

Closed
sswaroopgupta opened this issue May 5, 2016 · 5 comments
Closed

Unable to write to html report #67

sswaroopgupta opened this issue May 5, 2016 · 5 comments
Labels

Comments

@sswaroopgupta
Copy link
Contributor

sswaroopgupta commented May 5, 2016

$ gauge specs
Gauge.CSharp.Runner.GaugeProjectBuilder Building Project: Z:\Documents\Visual Studio 2015\Projects\usingTemplate\usingTemplate.sln
Gauge.CSharp.Runner.GaugeProjectBuilder Success
Gauge.CSharp.Runner.SandboxFactory Creating a Sandbox in: Z:\Documents\Visual Studio 2015\Projects\usingTemplate\gauge-bin
# kusfdsf sdfsdfsdf
  ## Scenario           Error Message: write tcp 127.0.0.1:52041->127.0.0.1:52044: use of closed network connection
        Stacktrace:


        Failed Step: sfdsf "ab"
        Error Message: Connection closed [127.0.0.1:52044] cause: EOF
        Stacktrace:

 F
    Error Message: write tcp 127.0.0.1:52041->127.0.0.1:52044: use of closed network connection
    Stacktrace:


Gauge.CSharp.Runner.GaugeListener System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.SEHException: External component has thrown an exception.
   at FluentAssertions.Primitives.StringEqualityValidator..ctor(String subject, String expected, StringComparison comparisonMode, String because, Object[] reasonArgs)
   at FluentAssertions.Primitives.StringAssertions.Be(String expected, String because, Object[] reasonArgs) in z:\Builds\work\eed5b735bfe0fb8d\FluentAssertions.Core\Primitives\StringAssertions.cs:line 38
   at usingTemplate.StepImplementation.SfdsfSfdwithSfda1(String sdf) in z:\Documents\Visual Studio 2015\Projects\usingTemplate\StepImplementation.cs:line 58
   --- End of inner exception stack trace ---

Server stack trace:
   at System.Threading.Thread.InternalCrossContextCallback(Context ctx, IntPtr ctxID, Int32 appDomainID, InternalCrossContextDelegate ftnToCall, Object[] args)
   at System.Runtime.Remoting.Channels.CrossContextChannel.SyncProcessMessage(IMessage reqMsg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)  Error Message: write tcp 127.0.0.1:52041->127.0.0.1:52044: use of closed network connection
  Stacktrace:


  Error Message: write tcp 127.0.0.1:52041->127.0.0.1:52044: use of closed network connection
  Stacktrace:

Unable to connect to plugin Html Report 2.1.1. proto: required field "SuiteExecutionResult.SuiteResult.SpecResults.ProtoSpec.Items.Scenario.ScenarioItems.Step.StepExecutionResult.PostHookFailure.StackTrace" not set

Unable to connect to plugin Xml Report 0.1.2. proto: required field "SuiteExecutionResult.SuiteResult.SpecResults.ProtoSpec.Items.Scenario.ScenarioItems.Step.StepExecutionResult.PostHookFailure.StackTrace" not set


   at Gauge.CSharp.Runner.ISandbox.ExecuteMethod(MethodInfo method, Object[] args)
   at Gauge.CSharp.Runner.MethodExecutor.Execute(MethodInfo method, Object[] args) in c:\Program Files (x86)\Go Agent\pipelines\Csharp-Build\Runner\MethodExecutor.cs:line 45
   at Gauge.CSharp.Runner.Processors.ExecuteStepProcessor.Process(Message request) in c:\Program Files (x86)\Go Agent\pipelines\Csharp-Build\Runner\Processors\ExecuteStepProcessor.cs:line 61
   at Gauge.CSharp.Runner.GaugeListener.PollForMessages() in c:\Program Files (x86)\Go Agent\pipelines\Csharp-Build\Runner\GaugeListener.cs:line 52
Specifications: 1 executed      0 passed        1 failed        0 skipped
Scenarios:      1 executed      0 passed        1 failed        0 skipped

Total time taken: 156ms
@sriv
Copy link
Member

sriv commented May 5, 2016

Can you also add some code to reproduce this please?

@sswaroopgupta
Copy link
Contributor Author

not able to isolate the scenario to reproduce this.
Creating a new project is working fine. However the older project continues to have this issue.

@AWBuchanan7
Copy link

AWBuchanan7 commented Aug 22, 2016

I am seeing a similar issue, seems to be happening specifically as I try to implement CefSharp, I've attempted to reduce this to as simple of a setting as I could, but the reality is I'm in over my head.

I was mostly just curious what it would look like to use CefSharp.Offscreen inside of Gauge.

Here is my working (see: no CefSharp) StepImplementation.cs file:

namespace Gauge
{
    public class StepImplementation
    {
        private IDocument document;
        private IConfiguration config;
        static ManualResetEvent resetEvent = new ManualResetEvent(false);

        [Step("The page <target> contains the script <parameter>.")]
        public void VerifyScriptFound(String target, String parameter)
        {
            // Setup the HTML parser
            var parser = new HtmlParser();
            // Setup the configuration to support document loading
            config = Configuration.Default.WithDefaultLoader();

            // Asynchronously fetch document in a new context using the configuration
            fetchDocument(config, target);
            resetEvent.WaitOne();

            // After document fetched find all <script> tags in the document that match
            IEnumerable collection = document.All.Where(element => element.LocalName == "script" && element.GetAttribute("src") == parameter);

            // Assert
            collection.Should().NotBeEmpty();
        }

        private async void fetchDocument(IConfiguration config, String target)
        {
            document = await BrowsingContext.New(config).OpenAsync(target);
            resetEvent.Set();
        }

    }
}

My console's output when I run Gauge with the above implementation:

Gauge.CSharp.Runner.SandboxFactory Creating a Sandbox in: C:\Users\brandonbuchanan\AppData\Roaming\gauge\plugins\csharp\0.8.0\bin\
Checking updates...
# Web Acceptance Testing
  ## The initial page is live    P

Successfully generated html-report to => C:\Workspace\Test\NewGauge\reports\html-report
Plugin [Html Report] with pid [7464] has exited
Specifications: 1 executed      1 passed        0 failed        0 skipped
Scenarios:      1 executed      1 passed        0 failed        0 skipped

Total time taken: 1.137s
Updates are available. Run gauge --check-updates for more info.

And now, here is my not working (see: CefSharp) StepImplementation.cs file:

using CefSharp;
using CefSharp.OffScreen;
using Gauge.CSharp.Lib.Attribute;
using System;
using System.Threading;
using System.IO;
using System.Threading.Tasks;

namespace Gauge
{
    public class StepImplementation
    {
        private static ChromiumWebBrowser browser;

        [Step("The page <target> contains the script <parameter>.")]
        public void VerifyScriptFound(String target, String parameter)
        {
            var settings = new CefSettings();

            // Perform dependency check to make sure all relevant resources are in our output directory.
            Cef.Initialize(settings, shutdownOnProcessExit: false, performDependencyCheck: false);

            // Create the headless Chromium browser.
            browser = new ChromiumWebBrowser(target);

            // An event that is fired when the first page is finished loading.
            // This returns to us from another thread.
            browser.LoadingStateChanged += BrowserLoadingStateChanged;

            // We have to wait for something, otherwise the process will exit too soon.
            Console.ReadKey();
            Cef.Shutdown();
        }

        private static void BrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
        {
            // Check to see if loading is complete - this event is called twice, one when loading starts
            // second time when it's finished
            // (rather than an iframe within the main frame).
            if (!e.IsLoading)
            {
                // Remove the load event handler, because we only want one snapshot of the initial page.
                browser.LoadingStateChanged -= BrowserLoadingStateChanged;
                var scriptTask = browser.EvaluateScriptAsync("document.getElementById('lst-ib').value = 'CefSharp Was Here!'");

                scriptTask.ContinueWith(t =>
                {
                    //Give the browser a little time to render
                    Thread.Sleep(500);
                    // Wait for the screenshot to be taken.
                    var task = browser.ScreenshotAsync();
                    task.ContinueWith(x =>
                    {
                        // Make a file to save it to (e.g. C:\Users\jan\Desktop\CefSharp screenshot.png)
                        var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot.png");

                        Console.WriteLine("Screenshot ready. Saving to {0}", screenshotPath);

                        // Save the Bitmap to the path.
                        task.Result.Save(screenshotPath);

                        // We no longer need the Bitmap.
                        // Dispose it to avoid keeping the memory alive. Especially important in 32-bit applications.
                        task.Result.Dispose();
                    }, TaskScheduler.Default);
                });
            }
        }
    }
}

And the console output from the above implementation:

Gauge.CSharp.Runner.SandboxFactory Creating a Sandbox in: C:\Users\brandonbuchanan\AppData\Roaming\gauge\plugins\csharp\0.8.0\bin\
Checking updates...
# Web Acceptance Testing
  ## The initial page is live
Unhandled Exception: System.ArgumentException: Cannot pass a GCHandle across AppDomains.
Parameter name: handle
   at System.Runtime.InteropServices.GCHandle.InternalCheckDomain(IntPtr handle)
   at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
   at gcroot<CefSharp::CefSettings ^>.->(gcroot<CefSharp::CefSettings ^>* )
   at CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , CefRefPtr<CefCommandLine>* commandLine)
 F

        Failed Step: The page "https://omitted.com" contains the script "omitted.js".
        Specification: specs\example.spec:14
        Error Message: Connection closed [127.0.0.1:28430] cause: read tcp 127.0.0.1:28428->127.0.0.1:28430: wsarecv: An existing connection was forcibly closed by the remote host.
        Stacktrace:

        Error Message: write tcp 127.0.0.1:28428->127.0.0.1:28430: use of closed network connection
        Stacktrace:


    Error Message: write tcp 127.0.0.1:28428->127.0.0.1:28430: use of closed network connection
    Stacktrace:


  Error Message: write tcp 127.0.0.1:28428->127.0.0.1:28430: use of closed network connection
  Stacktrace:

  Error Message: write tcp 127.0.0.1:28428->127.0.0.1:28430: use of closed network connection
  Stacktrace:

Unable to connect to plugin Html Report 2.1.1. proto: required field "SuiteExecutionResult.SuiteResult.SpecResults.ProtoSpec.Items.Scenario.ScenarioItems.Step.StepExecutionResult.PostHookFailure.StackTrace" not set

Killing Plugin Html Report 2.1.1

Specifications: 1 executed      0 passed        1 failed        0 skipped
Scenarios:      1 executed      0 passed        1 failed        0 skipped

Total time taken: 198ms
Updates are available. Run gauge --check-updates for more info.

Honestly it strikes me that there is more than one problem occurring here. If you have any thoughts I'd be interested in hearing them. For the time being I'm continuing to see if I can get to the bottom of this as well though..

Edit:
Appears that the above "Unhandled Exception: System.ArgumentException: Cannot pass a GCHandle across AppDomains." is probably a result of cefsharp/CefSharp#351 which would end up blocking me from proceeding with a CefSharp and Gauge stack either way. Not sure if the TCP issue here is related in any way.

@sriv
Copy link
Member

sriv commented Aug 23, 2016

Hey @BWBuchanan7 - I was about to suggest that this might be something to do with CefSharp itself, and then I saw your edit.

From the comments in the referenced issue, this one from one of the members, stood out for me.

Do you think the proposed workaround on the CefSharp comment works for you?

@AWBuchanan7
Copy link

AWBuchanan7 commented Aug 23, 2016

Hi @sriv I'm currently investigating the usage of CefGlue as I'm not sure what exactly is meant by the suggested usage of RedGate (see this comment).

I'll come back with an update about what I find in regards to using CefGlue though.

Having spent a couple hours playing around with CefGlue now I am convinced that CefGlue is not the appropriate solution for what I'm trying to do here. I also looked into another alternative, ChromiumFx and felt similarly.

It appears CefSharp is not tremendously far off from a solution to the problem mentioned above as per this pull request and given my current situation I would rather wait out to see if that is in fact the solution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants