Integrating Selenium With Neoload For UI Rendering

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Integrating Selenium with NeoLoad for

UI Rendering

Version 1.0
March 2021

CitiusTech has prepared the content contained in this document based on information and knowledge that it reasonably believes to be reliable. Any recipient
may rely on the contents of this document at its own risk and CitiusTech shall not be responsible for any error and/or omission in the preparation of this
document. The use of any third party reference should not be regarded as an indication of an endorsement, an affiliation or the existence of any other kind
of relationship between CitiusTech and such third party
Recipe Overview
Requirement Key Focus Area
▪ Performance of an application is important ▪ Have a better vision on the behavior of
to ensure great user experience and helps server under load by getting the rendering
in continuity of business operations time of the browser.
▪ Selenium with NeoLoad can give real ▪ The idea is to execute a Selenium script to
rendering time of the web page as selenium get the Page loading times (DOM Loaded,
will enable to execute client side code like Page complete, Time to First Byte), while the
JavaScript and load DOM in real browser load is generated by NeoLoad
▪ Ultimately giving an understanding of the
complete end user experience

2
Recipe Description
Pre-requisites Approach (Method)
▪ NeoLoad Tool(Version 6.2 and above) ▪ Setup Eclipse with the NeoLoad jar/ Maven
dependencies
▪ Eclipse IDE(Version 4.6 and above)
▪ Using the NeoLoad Drivers for selenium to
▪ Java Version “1.8.0_221” and above communicate with NeoLoad
▪ License module "Integration & Advanced ▪ Integrating the Selenium jar file with
Usage" should be enabled in NeoLoad NeoLoad
▪ Maven Repository and Dependency ▪ Generating load on multiple browsers using
▪ Download neotys-selenium-proxy.jar NeoLoad
▪ Extracting the response time for UI
https://github.com/Neotys-Labs/Selenium-
rendering
WebDriver-Java/releases/tag/3.0.1

Environment Details (Infrastructure support


details)
▪ NeoLoad integration has been tested on
Selenium versions: 2.53.0, 3.0.1 and
3.141.59
▪ 5 Concurrent browser ran smoothly on
16GB RAM with Intel i5 8th generation
processor

3
Selenium NeoLoad
▪ NeoLoad can be integrated with functional testing tools in order to measure the end user
experience on real browser while the server is loaded
▪ In-browser testing has become a requirement for functional testing and Selenium is a tool for
implementing these tests using real browsers
▪ NeoLoad imports end-user-experience metrics collected from functional testing tools i.e
selenium
▪ Both API scripts as well as the UI rendering scripts can be clubbed together in a single run, in
order to get the accurate results for UI rendering while the API scripts will put load on the server

4
Selenium NeoLoad: Features and Limitations
Features
▪ With this integration, we are able to gather browser-side metrics from real browsers by
automatically launching tests in Selenium during a NeoLoad test
▪ As selenium is an open source tool, the integration with NeoLoad adds a lot of value to capture
the UI rendering time
▪ We measure how fast HTML pages take to load, and also check JavaScript and CSS performances.
This is done using a combination of the graphical NeoLoad interface and some scripting to invoke
Selenium code
▪ The metrics gathered by tests run on browsers also provide a more accurate representation of
the user experience under load conditions
Limitations
▪ Identifying Dynamic Elements
• Selenium scripts are subject to any change in the UI, if there are any changes in the id or
name or path of the object, the script will fail
▪ Scalability
• Maximum of 5 to 6 real browser instances can be launched as these browsers will be
launched in the local machine and will utilize the machines resources when launched
together

5
Selenium Setup : Maven Dependency and Repository
▪ If there is an existing Maven project, then add the below dependency and Repository in the
Maven settings file (pom.xml)

6
Selenium Setup : Import Neotys Jars/Wrappers in Eclipse
▪ If it is a Non-Maven Project, then download the below jars and import it in eclipse
• Download NeoLoad jar files “neotys-selenium-proxy-3.0.1” and “neotys-selenium-proxy-with-
dependencies-3.0.1” from below link
• https://github.com/Neotys-Labs/Selenium-WebDriver-Java/releases/tag/3.0.1
▪ Add the Jars in Eclipse along with the rest of the Jars:
• Right click on Project > Select Properties > Java build Path then click on Libraries tab and
click Add External JARs and add the downloaded Jars

▪ Importing the wrappers:


• Wrapper allows quick and easy integration with existing Selenium test cases with minimal
changes to existing code. Page load times and any error messages are sent to NeoLoad as
external data
• Import the NLWebDriver packages along with the rest of the packages

7
Methods of Selenium Wrapper
Below are Methods of Selenium Wrapper along with their description:

Method Description
NLWebDriver is the constructor of the NeoLoad
NLWebDriver(Selenium
webdriver.
webdriver,Name of the NeoLoad User
This constructor allows to specify the project that is to be
Path, path to the NL project);
updated with the new/updated User Path.

NLWebDriver(Selenium Project path is optional.


webdriver,Name of the NeoLoad User If the project is not specified, the wrapper will use the
Path); currently opened project.

This method sends all the Selenium HTTP/HTTPS traffic


StartTransaction(Name of the current into a specific NeoLoad container.
transaction); This method needs to be used before the Selenium
actions related to a business transaction.

StopTransaction() This method stops the transaction.

8
Using NeoLoad Drivers in Selenium
▪ Below is an example of how to use the NeoLoad drivers in Selenium
• Instantiating NLWebDriver in Selenium
▪ WebDriver for any browser can be used and path should be specified in the program.Path of the
NeoLoad project should be specified which will trigger the Jar files for execution in the program
{
static NLWebDriver driver;
private static final String CHROME_DRIVER_PATH = "C:\\Selenium
Integration\\Selenuim_Integration_withNeoload\\chromedriver_win32_1\\chromedriver.exe";
static {
final File file = new File(CHROME_DRIVER_PATH);
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
}
@BeforeClass
public static void before() {
final ChromeDriver webDriver = new ChromeDriver(addProxyCapabilitiesIfNecessary(new
DesiredCapabilities()));

// projectPath of the NeoLoad project from where we will trigger execution of Jar files
final String projectPath = "C:\\Selenium
Integration\\Selenuim_Integration_withNeoload\\Neoload_SelenuimIntegration\\Neoload_SelenuimIntegration.nl
p";

driver = NLWebDriverFactory.newNLWebDriver(webDriver, "SeleniumUserPath", projectPath);


}

9
Using NeoLoad Methods
▪ Below is an example of how to use the NeoLoad methods in Selenium
• startTransaction(“Transaction name”) will capture the performance numbers for the actions
transactions and send the traffic to NeoLoad by creating a separate folder in NeoLoad with the
Parameter name which is passed in the method
• stopTransaction() will stop the current transaction
@Test
public void testrun() {
driver.startTransaction("homePage");
driver.get("https://jpetstore.aspectran.com/catalog/");
driver.manage().window().maximize();
driver.stopTransaction();
driver.startTransaction("Dogs");
driver.findElement(By.xpath("//*[@id='SidebarContent']/a[2]")).click();
driver.stopTransaction();
driver.startTransaction("BullDog");
driver.findElement(By.xpath("//*[@id='Catalog']/table/tbody/tr[2]/td[1]/a")).click();
driver.stopTransaction();
}

10
Exporting the Selenium Scripts
▪ Right-click on Eclipse project and select Export to a Runnable JAR file
▪ Select the path where the Jars should be exported
▪ Different Jars can be created having different browser, if cross browser rendering time is required.
These jars can be later integrated in NeoLoad and can be executed as single script

11
Integrating Jar file into NeoLoad (1/3)
▪ The User Experience scripts of Selenium are started by NeoLoad via the Java Test Script advanced
action
▪ Create User Path in NeoLoad: Right Click on User Path and select “New User Path” and rename it
with any desired name
▪ Drag and Drop “Java Test Script” from End user Experience under Advanced folder to the Actions
folder in the User Path
▪ Rename the script name to any appropriate name
▪ Create population for the created scripts by Clicking on the “+” button under the “Populations”
tabs under Design section

12
Integrating Jar file into NeoLoad (2/3)
▪ JRE is the path to the Java Runtime Environment executable on the LoadGenerator
▪ Attribute arg1 must be: -jar
▪ Attribute arg2 must contain the mode -Dnl.selenium.proxy.mode=EndUserExperience
▪ Attribute arg3 must contain the URL to the data exchange server on the NeoLoad Controller (-
Dnl.data.exchange.url=http://<ControllerIPAddress>:7400/DataExchange/v1/Service.svc/)
▪ Ensure to replace <ControllerIPAddress> by the IP address of the NeoLoad controller, for example:
"-Dnl.data.exchange.url=http://192.168.1.6:7400/DataExchange/v1/Service.svc/"
▪ Attribute arg4 must contain the path of the JAR file that was exported, either its absolute path or
the path relative to the custom-resources folder in the NeoLoad project: ${NL-
CustomResources}/myjar.jar

13
Integrating Jar file into NeoLoad (3/3)
▪ Click on the Run button after selecting the population and configuring the below values
• Set the duration policy to “By Iteration”
• Set “simulated user” value to the number of user with which the scripts has to be run
• Select the Load generators as Local host or any generator which is added
• Select the Load variable policy to “Constant”

14
Reports Generated by NeoLoad Tool (1/3)
▪ To view detailed report, navigate to “Values” tab under Results section
▪ Select the type as “External Data” and select the “Result” value from dropdown
▪ Min, Max, Avg response time is captured in this report along with the % of error, Median and
standard deviation
▪ Reports can be exported by selecting “Generate reports” from the tools dropdown
• The report can be exported in PDF, Word, HTML and XML format

15
Reports Generated by NeoLoad Tool (2/3)
▪ To view detailed Graphs for each transaction, navigate to “Graphs” tab under Results section
▪ Select the tab as “External Data” and drag and drop the graphs desired in the right hand side
section
▪ Graphs for Time to First Byte, DOM content loaded, On Load and document complete can be
viewed
▪ All the data related to the integration can be viewed under “External Data” in NeoLoad as data is
exported via External integration

16
Reports Generated by NeoLoad Tool (3/3)
▪ Below is the definition for Time to First Byte, DOM content loaded, On Load and document
complete which is viewed in the reports
• Time for First Byte: Is the number of milliseconds it takes for a browser to receive the first byte
of the response from your web server
• DOM Content Loaded: Time for HTML document to completely load and parse, without
waiting for stylesheets, images, and subframes to finish loading
• On Load: Time it takes to download and display an entire individual webpage. This includes all
page elements, such as HTML, scripts, CSS, images, and third-party resources. On Load time is
usually considered for UI rendering
• Document Complete: Is actually the point in time when all the content referenced in the HTML
is fully-loaded

17
Recommendations & Pitfalls
Recommendation Pitfalls
▪ NeoLoad integration has been tested on ▪ Scripts created for UI rendering using
Selenium versions: 2.53.0, 3.0.1 and Selenium cannot be used for large number of
3.141.59 concurrent users, since it consumes CPU
▪ Use assertions as safety nets so if something usage and resources, so it is recommended
goes wrong it would help to pinpoint quickly to test few users i.e. max 5 users
the root cause ▪ A new JAR is created whenever a code
▪ Before integrating with NeoLoad, test the modification is done in eclipse
Selenium script to ensure it is functional
▪ The Selenium server is programmed with
Java and hence it is important to use latest
version of JRE to avoid any run time errors

18
CitiusTech
Markets

CitiusTech
Services

CitiusTech
Platforms

Accelerating
Innovation

Thank You CitiusTech Contacts


Email ct-univerct@citiustech.com

www.citiustech.com

19

You might also like