Load testing authenticated users

2019-07-15 03:37发布

I want to do load testing with Visual Studio but i don't get the idea how to setup load testing with authenticated users.

Imagine my scenario. This should be a quite common problem:

  • a website where you need to authenticate with username and password.
    Perform a action that is only allowed for a authenticated user

What i have done so far:

  • i have already written UI tests with Selenium:
    (this is working quite nice)

UPDATE: My Selenium test class: I want to use this code with the load test.
This is a data-driven unit test project as you can see on method TestCase4529

[TestClass]
public class Scenario2
{
    private IWebDriver driver;
    public TestContext TestContext { get; set; }

    [TestInitialize]
    public void SetupTest()
    {
        this.driver = new ChromeDriver();
        this.driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 30);
    }

    [TestCleanup]
    public void TeardownTest()
    {
        this.driver.Quit();
    }

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\4529.csv", "4529#csv", DataAccessMethod.Sequential), DeploymentItem("4529.csv"), TestMethod]
    public void TestCase4529()
    {
        var userName = TestContext.DataRow["UserName"].ToString();
        var password = TestContext.DataRow["Password"].ToString();

        // UI Test logic
        var loginPage = new LoginPage(this.driver);
        loginPage.FillForm(userName, password);
        loginPage.LoginButton.Click();

        // Some assertions
    }
}

Now when i setup the load test in Visual Studio i am asked how many users should do something:

enter image description here

I am not getting what this number means:

  • Does it only mean number of simultaneous threads?
  • How can i get a connection between a user (defined in the load test) an a authenticated user in my Selenium test?

What i would like to achieve:

  • Each user defined in the load test should be a authenthenticated user in my selenium UI test.

May somebody give me an idea how to do that or what i am thinking wrong...

2条回答
Rolldiameter
2楼-- · 2019-07-15 04:15

A Visual Studio load test provides a way of running other tests repeatedly and simultaneously. It works best with Web Performance Tests but it can run unit tests and Coded UI tests.

When a "constant load" of (say) 25 users is selected then 25 test cases chosen from the "test mix" of the load test will be started. Whenever one of those test cases finishes another test will be chosen and started so that there are always 25 test cases being executed. That will continue until the end of the test run, which is normally either a test duration or a number of iterations. (Here "iterations" means number of test cases executed.)

Assuming "Web Performance Tests" are being used then those tests are responsible for providing the user authentication. A common way of doing that is to data drive the test and provide user names and corresponding passwords in that data. See here for more detail.

You question asks whether the "constant load" of 25 users means 25 threads. It means that 25 tests cases will be running at the same time, but it does not use Windows threads.

In response to comments:

I think you are misusing or misunderstanding the terminology of Microsoft's test environments. You may be able to have a Selenium test within the test mix of a load test although I have never done it. The user count and the data source are independent items. The user count is about how many simulated users are running tests at the same time. The data source is used by the test cases. If you have 25 users and one data driven test then that test should be started 25 times and those 25 executions should use the first 25 lines of the data source (assuming a Sequential or Unique access method).

查看更多
\"骚年 ilove
3楼-- · 2019-07-15 04:35

To provide user and password you have to check for QueryString Parameters in your recorded webtest and pass data through Data Source see the following images for more detail:

enter image description here

Then pass the recorded webtest into load test as follow:

enter image description here

查看更多
登录 后发表回答