Reputation: 3199
I am using htmlUnit from Java (Converted to run in .net) Details here
I am using the same logic as the example, using the web client and this works perfectly with my MVC3 Razor code/views.
The problem occurs when I have [Authorize]
above my views as they webclient can't access the page. Is there a way around this? How would I (if possible) set it to automatically log on? If I just parse a login page and do a submit with Admin/Password.. will this carry over to every page visited in this "session"
I have tried:
[SetUp]
public void Setup()
{
//Initiate WebClient
webClient = new WebClient();
//Login
var loginPage = (HtmlPage)webClient.getPage(properties.DomainNameToTest + "Account/Logon/");
((HtmlInput)loginPage.getElementByName("UserName")).setValueAttribute(properties.adminUsername);
((HtmlInput)loginPage.getElementByName("Password")).setValueAttribute(properties.adminPassword);
var action = (HtmlPage)loginPage.getElementByName("loginButton").click();
}
This works fine.
Upvotes: 2
Views: 574
Reputation: 692023
HtmlUnit is a web browser. It just doesn't have a graphical user interface: you have to tell it what to do using code. If you're able to access your page using a regular web browser, then just do the same thing with HtmlUnit, and it will work as expected.
Upvotes: 1