Performance testing UI with YSlow and Jenkins - jenkins

I have a web application, on which I would like to run Yslow. The tests would need to be integrated with Jenkins. The application has a login page. If I provide the application's url, if a valid user is not logged in the login page will be displayed. So how do I test performance using YSLow & Jenkins? Is it possible to automate the login part?

Since YSlow can generate a performance report from an input HAR file, I would use a proxy server to record the performance data while navigating the web-site with Selenium.
This way, you can independently measure the performance on a real browser (Chrome, Firefox, Safari...) or on a headless one like PhantomJS.
To proceed, first download browsermob proxy and unzip it:
https://github.com/lightbody/browsermob-proxy/releases
Then write the code to launch the proxy server and to run your scenario with a Selenium client. This example was written in Python, but you could write it the same way with some Java, Ruby, Javascript or PHP.
from browsermobproxy import Server
from selenium import webdriver
import json, sys
# setup the proxy server
server = Server(r"C:\Download\browsermob-proxy-2.1.0-beta-5\bin\browsermob-proxy")
server.start()
proxy = server.create_proxy()
try:
# setup the browser
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
# start collecting the data
proxy.new_har("google")
# login to a twitter account
driver.get("https://twitter.com/login?lang=en")
driver.find_element_by_css_selector(".js-username-field").send_keys("my name")
driver.find_element_by_css_selector(".js-password-field").send_keys("my password")
driver.find_element_by_css_selector("button.submit").click()
# save the collected data to a file
with open(sys.argv[1], 'w') as file:
file.write(json.dumps(proxy.har, indent=2))
finally:
driver.quit()
server.stop()
Finally, to run the script and generate the performance report with a command line:
python perf-login.py perf-login.har
yslow perf-login.har

yes you can, but you still miss this automated part. You need something more than a YSlow & Jenkins. It's highly depended on application's network architecture - if you run tests locally, or remotely.
Robotframework + Selenium Server
With Robotframework's selenium2library can use Selenium Server bindings to manipulate with browsers DOM. In other words, you can create very simple automated login tests and actions. Afterwards the SSHLibrary or Terminal library can run YSlow commands and you just need to provide output files to Jenkins readable location. It's pretty complex solution suitable for advanced network architecture with many dependencies.
PhantomJS + CasperJs
If you need to run your performance tests locally, you can use advantage of headless browser PhantomJS. In combination with CasperJS you are able to manipulate with DOM to create automated login processes. PhantomJS is also compatible with YSlow, so once again, you just need to define the output files location for Jenkins.
For both solutions (or any other) you will need additional jenkins plugins to read output files generated by YSlow.

Related

Rails headless browser testing without installing browser

We're doing some testing in Rails using a headless browser for our feature tests using RSpec and the web drivers gem: https://github.com/titusfortner/webdrivers to get the Chrome driver.
However we've had some issues whereby some developers don't have Chrome installed (and don't intend to) and also we have our app running on a Jenkins pipeline and we want to avoid having to install Chrome on the server for the tests...
Is it possible to run a headless browser without installing the actual browser as well as a hard dependancy on the system that the tests run on?
I've read conflicting articles that state headless allows you to still do your testing either when the system doesn't have the browser installed... but at the same time the documentation for Chrome and Firefox state the browser also needs to be installed when using their drivers.
https://github.com/rubycdp/cuprite I also came across this which bypasses the need for WebDriver etc... but still seems to have a hard dependancy on having Chrome installed on the system the tests run on.
You have to choose a browser:
Chrome: chromedriver
Firefox: geckodriver
Edge: edgedriver
Internet Explorer: iedriver
See https://github.com/titusfortner/webdrivers

Executing script on a UNIX server from PowerShell

I have a PowerShell script hosted in Windows Server 2008 R2. This script need to invoke a UNIX script residing in a UNIX server. After completion of execution of script it must return the output to the calling script. (PowerShell Script). I am implementing it in highly secured servers. Hence cannot use third party built tools/Libraries unless they are authenticated and approved by standards. If there is any standard library which I can make use of and accomplish this task will be appreciated.
There is no "native" way to do it that I'm aware of.
The most secure method I can think of offhand which will be accepted by your review board is to use ssh with keys for authentication. Yes, you'll have to acquire & install an SSH client for Windows, but if your servers are "highly secured" then your security people should be very happy to hear that you want to use SSH. SSH should already be running on the UNIX servers.
You can use ssh to execute any command on the remote system (that you're authorized to execute) instead of creating a login shell simply by appending the command to the end of the ssh command line (as described by the link above).

Performance monitoring of production site using Shell script and Selenium Web Drivers

I will shortly try to explain what I am trying to do here. I need to periodically check the response time of the my site by logging into the system and noting the time to load the welcome page.
I am doing this using Selenium WebDriver and Java. I am currently checking the response time using the org.apache.commons.lang3.time.StopWatch which start when user hits the login button and stops when welcome page renders completely. I check weather this response time is above threshold level and send mail to admin alerting him in case of slow response of system.
Currently, I have created the executable jar file which opens the web browser using Selenium WebDriver and check the response time. I have also created the job in Jenkins using DOS commands which runs periodically using cron schedular. This I'm doing in my Windows 7 pc and I have Jenkins installed on my localhost. The scheduled job builds on Jenkins periodically but I can't see any activity like opening the web browser and the further task explained above. It runs perfectly when I use windows scheduler to execute batch file. The ultimate goal I have, is to run the Selenium WebDriver tests on the Linux system via jenkins while Jenkins server has been installed on a Linux machine.
Any help will be great! Also let me know if anybody wants to see the code.

Viewing Selenium Scripts in Jenkins Server

I am using Jenking to run my selenium scripts on a remote server. My question is "Is there any way to visually see my scripts running on the server? I mean on an actual browser when scripts are running in Jenkins?"
No, you cannot visually see a browser running on ubuntu server but apart from that you can run a headless browser and log everything to see the progress of your scripts running on server.
Yes, either use a Sauce labs account, or just run tightVNC server on the remote system, which runs a vnc server in a "Java Viewer" and by setting a "readonly password" to the server, you can open a browser and using the java viewer, basically you can watch the session and you can even "scale" the size of the desktop just like Sauce Labs can do.

Jenkins - remote access denied

I'm using the ArtifactDeployer plugin to deploy the build job artifacts to a remote location (Windows share SMB).
However Jenkins never manages to succeed. Throwing errors like:
[ArtifactDeployer] - Starting deployment from the post-action ...
[ArtifactDeployer] - [ERROR] - Failed to deploy. Can't create the directory ... Build step
[ArtifactDeployer] - Deploy artifacts from workspace to remote directories' changed build result to FAILURE
Local deployment works fine.
The Jenkins machine OS is Windows 7 32-bit Prof.
Jenkins is running as a service using a local system account.
I tried using another account, my user account but the service failed to start (Windows error 1069: the service did not start due to a logon failure).
The network service account did run but than Jenkins throws errors it can't access the .NET framework.
When manually trying the remote copy, this works fine. I can create directories and write to it. On the same machine of course.
I tried two different remote reference in Jenkins:
1) \\targetdirectory
2) I:\ - by mapping a drive letter to the remote dir in windows
No success...
Any tips or suggestions? Thanks!
Update 15/02/2012:
Still no solution or workaround for this issue.
It's not only the plugin, I hit also this issue using "Execute Windows batch command".
I found a bug report that I want to share.
Solution
I found a solution. You have to grant access persmission to the computer in a domain instead of the user of that machine. Seems very logic if you look back to it.
A 2nd solution is to run the service using a domain user account. Above I made a mistake by using the local user .\user in stead of DOMAIN\user.
If you don't have a domain, the following will work for sure. This should work even if you have a domain.
Background Info:
You need your mapped drive to be mapped for the same account that the service is using AND be available at the right time. Normally mapped drives are mapped only for the logged in user, at the time that they log in. Service user contexts don't get "logged in" per se -- for example, if I map a drive as MyUser and the service runs as MyUser, the drive won't be available until I actually log in by typing in my password. However, we can use a script to map the drive at startup (instead of login) for a particular user. Jenkins normally runs as Local System Account, so if you don't want to change that, you'll need to run the script below as the SYSTEM user. You can instead create a specific user for Jenkins to run as, if you don't want to grant this mapped drive to all services/processes that run as SYSTEM, and run both the service and the script below as that user (this is probably more secure).
Solution Steps:
In ArtifactDeployer you want to deploy to a mapped network drive. In my case this is S:.
There is no special setup for permissions on the remote share. (In my case, a Windows Server 2008 share with a username and password that is used for mapping the drive.)
Write a batch file MapDrives.bat in a place that your chosen user (default: SYSTEM) has access to, with the following in it:
net use S: "\\server_name\share_name" /persistent:yes password_here /USER:username_here
Note that I am mapping to S: in that line.
Via Task Scheduler, create a task that runs as the same user as the service (default: SYSTEM), triggers At Startup, and as it's action, runs the batch file MapDrives.bat.
Reboot and it should work!
Citations:
After diving through many pages and many tests, ultimately, the best suggestions were found here, and led me to the above solution.
https://stackoverflow.com/a/4763324/150794
Make sure your 'local system account' has access rights to the remote directory (including write access). Then use the notation
\\targetdirectory
Mapping drive letters to remote directories only applies to the user account you are currently working with. The drive letter mapping will not be available to any other account.

Resources