I am using multiple webdrivers with different threads. However, drivers are consuming a lot of memory and cpu usage. I am looking for efficient solution which can utilise many drivers usage with low memory/cpu footprint.
I have the following code:
for (int i = 0; i < 200; i++) {
Thread t = new Thread(this::workWithNewWebDriver, "Browser" + i);
t.start();
}
public void workWithNewWebDriver(){
ChromeOptions bestPerformanceOptions = new ChromeOptions();
WebDriver driver = new ChromeDriver(bestPerformanceOptions);
driver.get("anysite.com");
// Do stuff...
}
I am currently using that kind of user tests with selenium but framework is subject to change and I am looking for most performant lightweight solution.
Tests are only requiring user login and interactions, Any framework can click the button with a user is okay by me.
I have already tested the headless option for selenium but it only gives a slight improvement to performance metrics.
Where can I find the preset of performant options for chrome driver?
How can I improve the performance of selenium that tests 200 different parallel users use case ie.?
I don't think you can, real browser means real browser and real browsers are resource intensive. For example Firefox 109 requires 1 CPU core and 2 GB or RAM per instance and Chrome tends to consume even more.
Moreover it is not recommended to use Selenium for performance testing in the Selenium official documentation, they suggest to use JMeter for that. Given you properly configure JMeter to behave like a real browser from the system under test point of view there will be no difference whether you use Selenium or JMeter for testing.
Related
I'm using selenium on python 3.5 with chrome webdriver on a ububtu vps, and when I run a very basic script (navigate to site, enter login fields, click), memory usage goes up by ~400mb,and cpu usage goes up to 100%. Are there any things I can do to lower this, or if not, are there any alternatives?
I'm testing out selenium in python but I plan to do a project with it in java, where memory usage is a critical factor for me, so the same question applies for java as well.
I believe your memory usage problem is caused by selenium. AFAIK it runs on webkit, which is also used by Googles Chrome browser. And chrome is well known for it's excessive memory usage.
This might help:
Selenium github issue #4988
Don't forget drive.close() in your code , if you don't close your driver, you will have a lot instance of Chrome.
This should not happen I believe unless there is a leak.
Please try install nmon on your machine and run the test.
Nmon
This would help in figuring out exact cause of high CPU utilization and resolve your issue.
I am using jxbrowser to make an automation test application.
After run a lot of automation tests(login to a webpage, click some button, perform some UI interaction), I reallize that the jxbroser-chromium.exe took so huge RAM, Even after doing some automation tests, I load "about:blank" page
Note that I use only one instance of Browser & BrowserView
Is there any way to clean & clear RAM when using jxbrowser?
JxBrowser is based on Chromium engine. Chromium engine is running in the jxbrowser-chromium.exe process. JxBrowser doesn't control the memory in this process. All memory management is done by Chromium engine. If you see that the process allocates too much memory, then it means that Chromium engine decided to allocate this amount of memory for some reasons.
I believe if you do the same automated tests in Google Chrome tab, you will see the same memory usage issue. As far as I know there's no Chromium API that would clear the memory of an existing tab/browser. To clear the memory I can only suggest that you dispose Browser instance and create it again.
I'm writing automated scripts to load thousands of records into the web application and the time frame in which data has to be loaded is very less. So I thought of using Selenium Grid to run the scripts in parallel to achieve lesser time. Now, My question is will this affect the execution time of the automated scripts or the hub machine. There will be around 20 machines or maybe even more connected to the hub.
Also, Is using selenium grid the best option for this or I could use some other approach as well. And, feeding data from database or using web services is not possible.
Thanks in advance.
will this affect the execution time of the automated scripts or the hub machine
Maybe. It depends on the rest of your stack. Is the underlying server multi-threaded; will each Selenium Grid instance be provisioned its own process on the server? What about your database - will transaction locking block the other processes? Will any of your servers hit some performance bottleneck? Is the database ACID compliant? - I.e. Will running multiple Selenium instances like this cause race condition errors?
There's only one way to know for sure: Do a trial run, and benchmark it.
Is using selenium grid the best option for this or I could use some other approach as well
If you have direct access to the database, then you could seed the data directly (using SQL, presumably). This would be much faster, if it's a viable option.
Also, it depends what you're typing to achieve here. Are you simply seeding the application with a tonne of data? (In which case, SQL is a better option.) Or, are you actually performance-testing the website? (In which case, intense parallel execution may be part of the specs.)
Inconsistency is the theme here. I have a large Selenium test suite that is giving me issues on a Mac. My coworkers use Windows and they are not experiencing any problems with it. Essentially when I run the whole suite using TestNG, the tests behave differently than when run individually. Individually, the tests complete without any problems. When run as a whole suite, currently about ten tests, the third test to be executed always hangs at the exact same spot. It tries to find an element and never comes out of the Selenium API. The point of no return is marked with the XXX below.
driver.manage().timeouts().pageLoadTimeout(20000, TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
try {
element = driver.findElement(By.xpath(xpathLocator)); // XXX
} catch (NoSuchElementException | org.openqa.selenium.TimeoutException e)
The suite is not being run in parallel. The same behavior is occurring across Chrome, Firefox, and Safari although the element that is being sought when the program hangs does change between browsers. I'm currently using Mac 10.10.6 with the latest versions of Selenium, Eclipse, and TestNG. The same behavior is occurring on separate Mac machines. The behavior is also the same whether I run the TestNG suite in Eclipse or from the command line. The entire suite is executed without any problems when logging is enabled on the node via -log someFile or when the node is running on a remote machine i.e. not locally. The suite is fairly large so if there's any other code I can post here that would be helpful in diagnosing the issue please let me know. Any ideas to point me in the right direction would be very helpful.
Placing timeouts and wait's are inherently subjective since the time a page takes to load can vary. The best thing you can do is place it in a while loop, but include a large timeout to force the code out of the while loop, or throw an error if the element cannot be found since it is a test after all.
int i = 0;
while (!driver.findElement(By.xpath(xpathLocator))
{
//timeout goes here
i++;
if (i == 10) throw new exception
}
something like this should do the trick
I think you should increase implicitlyWait from '0'.
I heard there are some HTML loading issues in Mac. By increasing the time value, it will solve DOM loading issues.
Selenium Document says this about implicitlyWait.
Implicit Waits
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instanc
I am able to execute maximum 5 test cases in parallel on one machine.
How to increase the number of test cases?
You'll typically be limited by the power of your computer (number of CPU core and memory speed and amount). This will relate to the number of browsers you open, and therefore the number of test you can run. To run more tests, faster, use a Selenium Grid, such as SauceLabs (which is free for a trial period).
I talk about this is the book I'm working on -- Selenium WebDriver In Practice.
Alex