AngleSharp.Js icon indicating copy to clipboard operation
AngleSharp.Js copied to clipboard

PageTests don't seem to work

Open VoidMonk opened this issue 9 years ago • 5 comments

Hi, I copied the two tests from PageTests.cs to a standalone executable for testing purposes, but query selector returns no results for some strange reason.

async static void RunScriptSelectorTest()
{
    var url = "http://html5test.com"; // same URL as in the test
    var sel = "#score > .pointsPanel > h2 > strong"; // same valid selector path as in the test
    var config = Configuration.Default
                .WithCss()
                .WithJavaScript()
                .WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true);
    var document = await BrowsingContext.New(config).OpenAsync(url);
    var elements = document.QuerySelectorAll(sel);
    // but no results (elements.Length is zero),
    // even though given selector has one match
}

Any ideas on what might be going wrong, as compared to the passing tests?

VoidMonk avatar Jul 18 '16 05:07 VoidMonk

Yes, the JavaScript part is not executing correctly. However, the exact reason is unknown. I doubt its something language specific, rather some part of the DOM model is missing.

If you would find out what the exact problem is that would be super awesome. But be aware that debugging this will be quite hard, as with most other JS part.

You'll basically need to open up the JavaScript files used by HTML5Test and add parts one-by-one (first in larger blocks, then in smaller chunks to drill down). I've done it a couple of times for jQuery (e.g., previously jQuery 2.x worked fine while jQuery 1.x didn't - it turned out that jQuery 1.x needed CSS to be loaded) and it always was quite a pain.

FlorianRappl avatar Jul 18 '16 05:07 FlorianRappl

Currently identified (i.e., potential) sources of the problem: #7, #12, #15, #21 #26.

FlorianRappl avatar Jul 18 '16 05:07 FlorianRappl

Tried a few simpler local test pages with inline as well as external JS, and it seems to work in most cases, so it looks like the issue occurs with larger, more complex JS parsing and/or execution (by Jint maybe?).

I'll try to look into it further.

VoidMonk avatar Jul 18 '16 06:07 VoidMonk

Well, I trust Jint so far that (since Sebastion also included a lot of ES5 official tests) I would rather see the problem in AngleSharp / AngleSharp.Scripting. After all the DOM is not complete (e.g., we have no renderer), where complete means: in the state where browsers use it. If a (JS) library author assumes he is working against "the browser" it may easily come to a conflict.

Yes, in small snippets this is usually no problem, but the larger chunks where lots of things happen are not as stable as I wish they would be.

I am currently finishing some other projects to get some more spare time such that I can come back to AngleSharp Scripting. I will try to implement #7 soon.

FlorianRappl avatar Jul 18 '16 07:07 FlorianRappl

(I doubt that #7 will fix this issue, but its required sooner or later anyway; so any help from you on this issue would be greatly appreciated!)

FlorianRappl avatar Jul 18 '16 07:07 FlorianRappl