4

We would like to automate certain tasks in a website, like having a user 'login', perform some functionality, read their account history etc.

We have tried emulating this with normal POST/GETs, however the problem is that for example for 'login', the website uses javascript code to execute an AJAX call, and also generate some random tokens.

Is it possible to literally emulate a web-browser? For example:

  • Visit 'www.[test-website].com'
  • Fill in these DOM items
    • DOM item 'username' fill in with 'testuser'
    • DOM item 'password' fill in with 'testpass'
    • Click' button DOM item 'btnSubmit'
  • Visit account history
    • Read HTML (So we can parse information about each distinct history item)
  • ...

The above could be translated into say the below sample code:

var browser = new Browser();
var pageHomepage = browser.Load("www.test-domain.com");
pageHomepage.DOM.GetField("username").SetValue("testUser");
pageHomepage.DOM.GetField("password").SetValue("testPass");
pageHomepage.DOM.GetField("btnSubmit").Click();
var pageAccountHistory = browser.Load("www.test-domain.com/account-history/");
var html = pageAccountHistory.GetHtml();
var historyItems = parseHistoryItems(html); 
1
  • try Fiddler to do this. Commented Jun 20, 2013 at 13:58

4 Answers 4

2

You could use for example Selenium in C#. There is a good tutorial: Data Driven Testing Using Selenium (webdriver) in C#.

Sign up to request clarification or add additional context in comments.

2 Comments

If the goal is to use .NET, the Selenium C# bindings are good, or you can use Selenium with IronPython as well. Lately I prefer IronPython over C# for automated GUI/browser tests in .NET.
This tutorial is outdated, a better one is available here.
1

I would suggest to instantiate a WebBrowser control in code and do all your work with this instance but never show it on any form. I've done this several times and it works pretty good. The only flaw is that it makes use of the Internet Explorer ;-)

Comments

1

Or just try System.Windows.Forms.WebBrowser, for example:

this.webBrowser1.Navigate("http://games.powernet.com.ru/login");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
     System.Windows.Forms.Application.DoEvents();
HtmlDocument doc = webBrowser1.Document;
HtmlElement elem1 = doc.GetElementById("login");
elem1.Focus();
elem1.InnerText = "login";
HtmlElement elem2 = doc.GetElementById("pass");
elem2.Focus();
elem2.InnerText = "pass";

2 Comments

And can you simulate a click on an anchor link, which actually contains javascript code? (e.g: <a href="javascript:alert('hello world');">Click here</a>)
Yep, I can: foreach (HtmlElement elem in doc.GetElementsByTagName("a")) { Console.WriteLine(elem.InnerHtml + "->" + elem.DomElement); elem.InvokeMember("Click"); }
0

Try JMeter, it is a nice too for automating web requests, also quite popularly used for performance testing of web sites

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.