简体   繁体   English

在负载下运行Selenium WebDriver测试

[英]Running Selenium WebDriver tests under the load

I have bunch of functional tests for a web application which were written using Java, Selenium WebDriver and TestNG. 我有一堆使用Java,Selenium WebDriver和TestNG编写的Web应用程序功能测试。 Currently my goal is to measure the time of each method in those tests under the load(for instance with 10-15 users working simultaneously). 当前,我的目标是测量负载下这些测试中每种方法的时间(例如10-15个用户同时工作)。 Did anyone face such problem and maybe has an idea how to do it? 有没有人遇到这样的问题,也许有一个想法怎么做? Or it is impossible to use WebDriver in case of load tests? 还是无法在负载测试中使用WebDriver?

I was searching for resolution with jMeter + jUnit as jUnitRequest(rewriting my tests from TestNG to jUnit won't be difficult) but as far as I know jUnit doesn't support such tests when one method depends on some other(TestNG support this) and I have to merge all methods to only one(which imho is stupid idea). 我正在使用jMeter + jUnit作为jUnitRequest搜索分辨率(将我的测试从TestNG重写为jUnit并不困难),但据我所知,当一种方法依赖于其他方法时jUnit不支持此类测试(TestNG支持此方法)而且我必须将所有方法合并为一个方法(恕我直言是愚蠢的想法)。

Any hint how to handle this problem will be highly appreciated. 任何提示如何处理此问题将不胜感激。

It's not that hard to do it with TestNG. 使用TestNG并不难。 But in order to run you tests in parallel, you'll have to manage your WebDriver with your threads. 但是为了并行运行测试,您必须使用线程来管理WebDriver。 To do that, I would create a class with a ThreadLocal. 为此,我将使用ThreadLocal创建一个类。 With the TheadLocal class, you can easily manage your objects per thread. 使用TheadLocal类,您可以轻松管理每个线程的对象。 There is an example of such a class : 有这样一个例子:

public class DriverManager {

    private static ThreadLocal<WebDriver> driver = new ThreadLocal<WebDriver>();

    public static WebDriver getDriver() {
        return driver.get();
    }

    public static void setWebDriver(WebDriver driver) {
        driver.set(driver);
    }
}

Whenever you have to use your driver, you just have to call it like that : 每当您必须使用驱动程序时,都只需要这样调用即可:

DriverManager.getDriver().doSomething

And then, with testNG, you can execute your tests in different threads. 然后,使用testNG,您可以在不同的线程中执行测试。

I would recommend not doing load testing with selenium. 我建议不要使用硒进行负载测试。 Load testing with a browser does not make sense. 使用浏览器进行负载测试没有任何意义。 Testing client side performance should only test performance with 1/2 browsers running as a client will only be running 1/2 instances of your application. 测试客户端性能仅应在运行1/2个浏览器的情况下测试性能,因为客户端将仅运行应用程序的1/2个实例。 They are never going to have 10-15 browsers open and running against your application. 他们永远不会打开10-15个浏览器并针对您的应用程序运行它们。 If you want to load test server side code you should use Jmeter and hit the API with users in parallel to determine how many parallel operations your server can handle before the server fails to respond. 如果要加载测试服务器端代码,则应使用Jmeter并与用户并行访问API,以确定在服务器无法响应之前服务器可以处理多少并行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Selenium WebDriver,Selenium Grid和testNG运行并行测试 - Running Parallel Tests using Selenium WebDriver, Selenium Grid and testNG 使用Web界面或任何可视化工具运行Selenium WebDriver测试 - Running Selenium WebDriver tests using Web interface or any Visual tool Selenium Webdriver测试在执行一段时间后停止运行 - Selenium webdriver tests stop running after some time of execution 在Firefox上运行Selenium WebDriver测试不再适用于Ubuntu - Running Selenium WebDriver tests with Firefox no longer works on Ubuntu 在使用 Java 运行一些 Selenium WebDriver 测试之前清除缓存 - Clear cache before running some Selenium WebDriver tests using Java Selenium WebDriver在后台运行 - Selenium WebDriver running in background 使用 selenium-webdriver 运行测试时访问远程计算机剪贴板上的数据 - Accessing data on remote machine's clipboard when running tests using selenium-webdriver 是否可以使用 JSCover 或任何其他工具来获得在浏览器中运行 Java Selenium WebDriver 测试的 JavaScript 代码覆盖率? - Is it possible to use JSCover or any other tool to get JavaScript code coverage running Java Selenium WebDriver tests in Browser? 使用testng在一个浏览器中跨多个类运行Java Selenium Webdriver测试 - Running java selenium webdriver tests across many classes in one browser using testng 硒测试卡住而没有运行 - selenium tests stuck and not running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM