-1

I'm using Selenium, I make many calls to INavigation's GoToUrl method throghout the application. The second call causes it to crash the application, or exit with exit code 0, no exception given.

It's got path for execution, I've attached a debugger to the exact line, even running through immediate window also crashes it.

I've since understood that its because of my usage of https://github.com/commandlineparser/commandline and letting it handle the execution, although why is this happening? Is it a bug of the package?

Option A - Works fine (no crash)

public static async Task Main(string[] args)
{
    var host = Host.CreateDefaultBuilder()
        .ConfigureServices((context, collection) => ServiceCollection.AddServices(collection, context.Configuration))
        .Build();

    var commandHandler = host.Services.GetRequiredService<CommandHandler>();
    var options = new BasicReportOptions()
    {
        UrlsToCheckFile = "...",
        DuplicateUrlsToCheckFile = "...",
        FocusedPhrasesFile = "...",
    };
    await commandHandler.HandleBasicReport(options);
}

Option B - Doesn't work (crashes) with the difference being the call to CommandHandler's HandleInputAsync (below) being called instead of the actual method.

public static async Task Main(string[] args)
{
    var host = Host.CreateDefaultBuilder()
        .ConfigureServices((context, collection) => ServiceCollection.AddServices(collection, context.Configuration))
        .Build();

    var commandHandler = host.Services.GetRequiredService<CommandHandler>();
    await commandHandler.HandleInputAsync(args);
}

HandleInputAsync:

public async Task HandleInputAsync(string[] args)
{
    Parser.Default.ParseArguments<BasicReportOptions, ExtensiveReportOptions>(args)
        .WithParsed<BasicReportOptions>(async options => await HandleBasicReport(options))
        .WithParsed<ExtensiveReportOptions>(async options => await HandleExtensiveReport(options));
}

So it seems to me that, when using HandleInputAsync and calling the methods without WithParsed, causes calls to Selenium's IWebDriver to crash?

  • Sure. `throw new Exception("testing");` seems to throw an exception. No exception is being thrown for my issue. It's simply just halting execution. – kakay rivera Aug 29 '23 at 15:14
  • @Tudeschizieuinchid my question is, why is the usage of (https://github.com/commandlineparser/commandline), causing sequential calls to internal Selenium methods to exit execution of my main process, which I feel I've made fairly clear. – kakay rivera Aug 29 '23 at 15:15
  • @devlincarnate as I've said, no exception is being thrown. Execution is simply ending without an exception. – kakay rivera Aug 29 '23 at 15:16
  • @devlincarnate As I also said, I've put a breakpoint on the exact line, trying it via the debugger and immediate window, both seem to halt execution with no signs of exceptions. – kakay rivera Aug 29 '23 at 15:17

1 Answers1

0

Basically gotta use MapResult of the package, it handles async better

public async Task HandleInputAsync(string[] args)
{
    await Parser.Default.ParseArguments<BasicReportOptions, ExtensiveReportOptions>(args)
        .MapResult(
            (BasicReportOptions opts) => HandleBasicReport(opts),
            (ExtensiveReportOptions opts) => HandleExtensiveReport(opts),
            errs => Task.FromResult(0));
}