0

I have a unit test which simulates a login on Uber. The goal is to acquire a token that isn't otherwise accessible without an interactive login. I've had this working in the passed but it appears the Uber login experience has changed and now I'm having issues getting NHtmlUnit to successfully submit the login button.

Here's my latest attempt: https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L100

Here's the key area:

var loginFormButtons = loginForm.GetElementsByTagName("button");
Assert.IsNotNull(loginFormButtons);

var loginButton = (HtmlButton)loginFormButtons.First();
Assert.IsNotNull(loginButton);

var loginButtonText = loginButton.AsText();
StringAssert.Contains("sign in", loginButtonText.toLowerCase());

loginButton.SetAttribute("type", "submit");
loginForm.AppendChild(loginButton);

var consentPage = (HtmlPage)loginButton.Click();
Assert.IsNotNull(consentPage);

I know the code is verbose, but unit testing NHtmlUnit is a nightmare. I've also tried a ton of different permutations, but they pretty much all end up with a HtmlButton.

Everything works great until https://github.com/wadewegner/uber-sdk-for-net/blob/42fd845fe43e11e3153b07d830ed40e3577b1ed3/src/UberSDKForNet.FunctionalTests/Tests.cs#L174. What I'd expect is for this to take me to the consent page where I'd either allow or deny the Uber app access to my information. However, it appears to simply reload the original page and consentPage appears to simply be the same as loginPage.

Any NHtmlUnit experts who might have some ideas?

The only thing I'll also point out is that in the past I was able to successfully use HtmlSubmitInput instead of HtmlButton but this appears to be one of the changes made by Uber. Perhaps this is part of the problem?

Wade
  • 741
  • 1
  • 5
  • 18

1 Answers1

0

Well, it's not perfect, but it appears setting the WebClient to FIREFOX_17 instead of CHROME solved it.

var webClient = new WebClient(BrowserVersion.FIREFOX_17);

See here: https://github.com/wadewegner/uber-sdk-for-net/blob/ceb1cdf80cebb31608744c050b649ddd6a75fb7a/src/UberSDKForNet.FunctionalTests/Tests.cs#L107

Wade
  • 741
  • 1
  • 5
  • 18