Selenium performance with .NET and Jenkins - How to profile and improve it? - asp.net

I have an ASP.NET website that I want to test with Selenium. I want to setup a Jenkins instance on a "staging" virtual machine, to run the tests automatically.
The problem is that the tests run very slowly - several times slower than on my development machine. A single, simple test can take more than 2-3 minutes.
I'd like to know if this is to be expected, if there are any obvious pitfalls for such a testing setup as mine, and if there's anything I can do to profile and improve the performance of the test suite.
Info:
Tests run on a 2.7GHz 2GB Ram virtual machine with Windows 7 64bit.
My dev machine is similar, but with a 32-bit Win installation.
The following is done by Jenkins:
The website gets checked out from source control, and configured with a custom web.config. The main differences are that it's compiled in release mode and it connects to a database on a different machine(also a virtual machine, on the same server).
IIS is monitoring the website's directory and automatically reloads changes.
The following command is run (directories sanitized): nunit-console Selenium-Project-Dir /labels
The tests are run on the Chrome webdriver.
The selenium project uses NUnit and WebRunner.
Driver instances are created once - before all tests, in a [SetUp] attribute inside a [SetUpFixture] class. They are deleted once, in the class's [TearDown] attribute.
A sample test looks like this:
[Test, Combinatorial]
public void AnExistingUserCanLogin(
[ValueSource(typeof(Drivers), "Good")]
IWebDriver driver)
{
// This function clicks on some buttons and fills in some forms.
LoginUser(driver);
// Make sure the user is now logged in
Assert.IsTrue(driver.ElementIsPresent(By.ClassName("imgUserAvatar")));
Assert.IsTrue(driver.ElementIsPresent(By.CssSelector("a.my-profile")));
Assert.IsTrue(driver.ElementIsPresent(By.CssSelector("a.logout")));
}
(The "Drivers" class contains lazily-instances webdriver instances of FF, IE, Chrome. You can guess what the "Good" static property of the class instances)

The fact that it is a VM should not be a problem, and RAM sounds like it is good. What OS is being run though? Some of the Windows OS have significant speed differences between the different bit versions (because of demands on hardware). This is especially noticeable in Vista but I have noticed a difference between Windows 7 and Server 2003.
I have found that there is a huge problem if the machine running the 64bit VM is a 32bit machine. It often seems to work well for a while and then as it continues to run tests will slow down. Which should be a duh but the main thing is that there may be too many VMs being run from the same place. Other programs will be affected by this and that can help troubleshoot if your VMs are on a company farm.
The other factor that has made a significant difference is if you are running the tests against different browsers. IE8 and IE9 will take the same selenium command and run them at different speeds. I don't know why this is, I just know that I have seen it. Make sure the staging machine has the current version of Chrome (or at least the same as your dev machine).
How the staging machine is networked to the database might be making a difference. This seems like a very small chance but if there is firewall crap between the two VMs that can have significant impact on time.
The only other thing I can think of that might be changing the length of time is if there are other programs being executed on the on the staging machine at the same time. Checking the CPU usage might helpful. Personally, I have noticed that my VM uses a lot more of the CPU than my personal machine. If this is the case the only solution I have found so far is to give the VM more processing power or to only run the test and nothing else.
Good luck!

Related

Chromedriver is extremely slow on a specific machine using Selenium Grid and .net

Overview:
Chromedriver works normally on one machine but extremely slowly on two other identical machines.
Setup:
Selenium Webdriver using .Net for coding and Selenium Grid for distributing the tests. MSTest is being used from within Visual Studio 2010 in order to run the tests.
A 64bit Windows 7 local machine acting as the Hub
Three 32-bit Win 7 remote machines (two of them are virtual) on my local network all configured as nodes. Here is the command used to start the nodes on the remote machines:
java -jar c:\seleniumWebDriver\seleniumGrid\selenium-server-standalone-2.31.0.jar -role node -hub http://XXX.XXX.XXX.XXX:4444/grid/register -browser "browserName=chrome",maxInstances=4 -Dwebdriver.chrome.driver="C:\seleniumWebDriver\chromedriver.exe"
The driver is launched like this from within the code:
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, browser);
driver = new RemoteWebDriver(new Uri(hubUrl), capability);
The variable "browser" and "hubUrl" above is passed via an app.config file that is built at runtime. For this case, browser=chrome.
Problem:
When I setup machine 212 (which is a virtual machine) as a chrome node using the command above, and then launch the scripts from the hub, I see chrome start in the proper remote machine and run normally. It fields between 5-10 commands per second.
When I setup either machine 78 (virtual machine) or machine 103 (real machine) as a node in the same manner, and then launch the scripts from the hub, I see the node start up chrome properly. However, it runs extremely slowly, like 1 command per sec or less.
Other info:
Like I said, on one machine chrome works normally, but on the others, runs extremely slowly. Firefox and IE, when configured as nodes, work normally.
I have compared the machine 212 (which works properly) with the other machines and cannot find the difference. All the machines are using 'selenium-server-standalone-2.31.0.jar' and the same version of the ChromeDriver.
It does not appear that the node machines are being overloaded. Also, it is a very consistent difference in performance which does not seem related to any fluctuating load on the network or the machines.
My network tech has verified that all these machines are configured identically on the network.
Has anybody seen anything like this before?
EDIT 1: I logged in today and all three remote machines are running chrome slowly. Before one of them was normal, but now they are all slow.
I ran into a similar issue where chromedriver was slow in some machines and it turned out to be a proxy issue. Disabling "Automatically detect settings" under Chrome://settings >Change proxy settings> LAN Settings> made webdriver execute commands faster in chrome for me.
My proxy settings were not using automatic detection, but I found the following helped a lot. The time it took to start the driver went down from 43 seconds to 1 second
driver = new ChromeDriver(new ChromeOptions{Proxy = null});
Bug link in chromedriver issues This is long lasting issue that got lowest priority. But as more user will vote for it maybe someone will fix it. It could also be releated to Parsing of proxy configuration is not standard compliant which will be fixed soon.
This code solved the problem for me for Chrome 75 on macOS 10.14.3
ChromeOptions options = new ChromeOptions();
options.setProxy(null);
driver = new ChromeDriver(options);

How to run automated GUI tests on a remote headless ESXi Virtual Machine?

I'm trying to setup automated GUI tests in ESXi Virtual Machines using TestComplete. The problem, as I understand it, is that when no remote desktop connection is made to the ESXi virtual machine, then it is impossible for TestComplete to perform screen captures and therefore automate the GUI testing. As far as I understand it, this is due to the fact that Windows does not generate any user interface when nobody is viewing it.
I'm sure other have experienced this problem. How did you solve it ? Are you using a third party computer which automatically launch remote desktop connections prior to running the tests ?
Would it be possible to launch a remote desktop from a head-less virtual machine to another to fake somebody viewing ?
Any other smarter solutions I haven't thought about ?
You should be able to log in to Windows on the VM's console using the vSphere client, then close vSphere, and Windows will still believe the user is viewing the console. Simple as that. :)
So there shouldn't be a need to involve remote desktop in the mix.
As long as your tests then run as that logged-in Windows user, you should be fine.
This technique has always worked like a charm for me with certain Watir, Selenium, and MS UI Automation tests that depend on having an interactive desktop.
If you need to reboot the VM automatically before/during the test, instead of logging in manually in the vSphere client, you can make Windows log in as an arbitrary user automatically - check the "control userpasswords2" command, or you can use the Sysinternals app "Autologin":
http://technet.microsoft.com/en-us/sysinternals/bb963905
Only catch with this technique is that you need to be able to launch your tests while not viewing the console on the VM, but it sounds like you've already taken care of that?
If you need a solution for launching your tests remotely, I highly recommend using Jenkins or Hudson to kick off tests/collect results from the VM. Jenkins has changed my life in this regard.
You may consider using the Network Suites functionality of TestComplete:
http://smartbear.com/support/viewarticle/16849/
It can open Remote Desktop connections on its own, control tests on remote PCs, and pull the logs back to the "master" project. This feature is designed to be used for distributed tests, and looks like it's just what you need.
As for opening RDP to a head-less VM, it should not be a problem - it's up to Windows to "think" about this. You just open RDP and it works even if there is no monitor attached to the remote PC/VM.
I hope this helps,
Alex
You can always use VNC with checking the option "Do nothing" when disconnecting viewer. This way you'll trick windows to generate the image.

CSS cross browser compatibility on Ubuntu

I'm currently working in web development and my default desktop is Ubuntu and I'm kind of happy with the setup and applications I got going. But I need to test web pages for cross browser compatibility while still being on Ubuntu.
I have gone through hell trying to get IE7 or IE8 (with wine) to run on ubuntu and when they finally worked they were very buggy and the graphics/scrolling was insanely slow.
Of course there is the option of virtual box but again, too much GBytes just to run a small application!
So to all the CSS gurus out there, how can I continue with my beloved Ubuntu and still deliver a good quality (tested) page.
Thank you.
Edit:
Update for freshness:
I now use the paid service from browserstack.com to provide the multitude of different browser testing environments via flash tunnelling. I'm a paid user, but there is an initial free trial period. browserstack has freed me of the need to run the windows os on my machines in any form, virtual image or otherwise. Since it also allows tunnelling, I can host the site on my local machine but still test in browserstack browsers. I consider the monthly fee money very well spent.
End Edit
Various options I have tried, including "the final solution": free downloadable windows testing OSes from microsoft
I've tried a number of the options below, but virtualbox may be your best bet for full & complete testing, especially because in a professional capacity you often have to test ie8, ie7 -and- ie6. Which gets tricky with only a single os installed. So in order of simplest and most shallowly testing to most complex and most fully testing:
browserlab.adobe.com
A newer, interesting online solution is: browserlab.adobe.com. It's actually very specific and fast compared to browsershots. It only gives you screenshots, but it's a great first step. So I do recommend that for purely visual (and thus relatively shallow) testing.
Browsershots.org
And while browsershots.org is also something that you should use for an overview experience of what users might see, you really can't get by without the real browsers for javascript and behavior testing (instead of just display & rendering testing that browsershots provides). The delay before you can see the images is also killer.
Dual booting into windows
Another that I've tried is dual booting, I work 99% of my time in ubuntu, and I have windows installed & available to dual boot into. Not a fast way to test, but if you don't have any other way to access ie, it should work for at least the latest version.
Remote desktop-ing over to a running windows box
Before I mention the "covers-all-the-bases" option, another useful possibility is to set up a windows machine and boot it up and connect to it via remote desktop so that you can work from one machine and test from both.
The final solution, using virtualbox
Finally, the mother of all solutions, using virtualbox:
Luckily (I know you said you didn't like the virtualbox solution, and I know it's an annoying setup process, but...) Microsoft provides available-for-a-year-or-more virtualmachine distros with different versions of ie pre-installed, available without the need for a license for a year or so before you'd have to update the virtualmachine, #
http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en
Installing a virtualmachine from microsoft's freely available browser testing images
Because this guide to setup on ubuntu is no longer available in full anywhere else, just in case you or someone else actually need it I feel compelled to include the actual details of the install process that were suggested to me on the ubuntu forums and worked when I went through them. I apologize for their length. Courtesy of the now anonymous original poster on the ubuntu forums:
Free Access to Microsoft Browser Compatibility Virtual OSes, Install Steps for Ubuntu
http://ubuntuforums.org/showthread.php?t=1097080 (Ed: I can't find this thread online any more)
HOWTO: run IE6, IE7, IE8 on Linux in
VirtualBox You need: virtualbox, qemu,
wine
Code: apt-get install virtualbox qemu
wine
Download the free(!) Microsoft
Internet Explorer Application
Compatibility Check VPC Images here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&displaylang=en
(Note: you don't have to download the
full pack, you can cherry pick
specific combinations of XP/Vista and
IE6-8)
Extract the VPC image(s) with wine
(double-click). (Note: it might take a
while before the first window shows
up)
Turn the VPC image(s) into (a) VMWare
image(s) (which is/are readable by
VirtualBox): qemu-img convert -f vpc
image.vhd -O vmdk image.vmdk
Setup a new VM in VirtualBox, using
the vmdk image as an existing disk.
Boot it, you will see the Windows boot
progress bar and ... it will BSOD
shortly after.
Fixing the BSOD:
The BSOD is caused because the virtual
Windows tries to load processor
drivers for the wrong processor (it is
not running on VirtualPC proc, but on
VirtualBox proc). Or something like
that... We need to force Windows not
to attempt to load drivers for the
processor (it doesn't need any proc
drivers, because it's all virtual
anyway). Start safe mode by
(frantically) hitting F8 at Windows
boot and choosing safe mode.
Ignore all the 'New hardware' detected
warnings (we will deal with those
later). Start a command box and run
the following command to disable the
loading of processor drivers:
Code: sc config processor start=
disabled (note the space between '='
and 'disabled'!)
Restart the virtual Windows, it should
now boot all the way to the Windows
Desktop.
Now just when you think you can start
browsing the web with IE, you will
find out that the virtual Windows
needs to install the drivers for the
AMD PCnet NIC, which are located on
the Windows install disk. Fortunately
for those without a Windows install
disk, there is another way :)
Download AMD PCnet drivers here:
http://www.amd.com/us-en/ConnectivitySolutions/ProductInformation/0,,50_2330_6629_2452%5E2454%5E2486,00.html
Make an iso file containing the
drivers. I used Brasero for
simplicity. Choose to create a Data
Project, add the zip file (or the
unzipped files, saves you a step in
Windows), create the iso. No need to
burn an actual cd!
Stop the virtual Windows, edit the
settings in VirtualBox: mount your
brand new iso.
Start the virtual Windows, when it
asks to install the drivers for the
PCnet nick, point it to the (unzipped)
drivers. Et voila! You have teh
innernets! (Now you can also try to
install the other drivers it complains
for, but it's not really necessary)
The image README says the image will expire after about a year. In my experience the system gets hobbled against multi-hour use, but is still usable for the kind of short periods that you might want when booting up to test a website. At worst you might have to go through these steps again, so be sure to put them somewhere where you can find them again after a year or so.
I think setting up a virtual machine (Virtualbox or VMWare or...) with a proper Windows will be your only (local) option.
I you don't have one, buy a used Windows XP license. XP is cheap (around 20-30 euros here in Germany, for example) and all relevant versions of IE run on it. Home edition is enough. No need for Windows 7 or anything.
You could install IETester on that to get all the IE versions on one OS. IETester has flaws and is not always 100% reliable in what it renders, but for a general CSS compatibility check it should be okay.
I've never tried IE using Wine, but even trying to imagine the combination gives me goose bumps :D
If you have a copy of Windows you could install it in a virtual machine (Virtualbox is a good, free option). Or if you don't mind a lot of lag time and publicly exposing your web pages you could use a service like BrowserShots.
I have not tried this on Ubuntu or anything but windows - but this seems to be a pretty good testing system over the web.
http://spoon.net/browsers/
however, I think your best result would be to use a VM if possible.
I have to add my voice to those opting for VirtualBox.
VMs are the only way to get an accurate representation of how IE platforms behave. They also allow you to keep your main Linux install free of WINE and IE gunk, which is otherwise always troublesome and fragile. (Especially if you're trying to run multiple IEs, which is unreliable and inaccurate even under Windows).
They're not necessarily that big, if you take care to prune the unneeded features, turn off swap, compact the disc image and so on. My XPSP3 test image is just over 800MB.
I didn't want to install all this stuff as I wanted to move forward quick.
I found public AWS images with pre installed browser that you just can start and use.
http://www.hens-teeth.net/html/products/cross_browser_testing.php
If you already have an AWS account this will take you only 5 min. Make sure that you enable the RDP port on the incoming traffic in your security group.
As I use ubuntu I was looking for a way to connect from it to MS Win.
I'm connection on to them via remote desktop.
The way to go here is rdesktop, a command line utility for Windows Remote Desktop. (sudo apt-get install rdesktop)
If you feel like a GUI use tsclient. It's very close to the windows version.
From a work flow perspective I develop for Chrome in Ubuntu first, then have a look at the other browsers via browserlab.adobe.com.
After that I start my new AWS instance to debug.
The small AWS Windows instance is a $0.12 per hour (http://aws.amazon.com/ec2/#pricing). I can work for a long time on that before it's worth installing all this stuff.
CrossBrowserTesting.com works from Linux. Allows you to access Mac, Windows, and Ubuntu configurations and all the browsers loaded on them via vinagre vnc client.

Setting up IIS7.5 for local ASP.Net Development

Are there any particular settings one should optimally enable/disable/tweak when doing ASP.Net MVC development on local test machine Windows 7 using IIS 7.5 and moving in and out the debugger & recompiling refrequnetly (integration/troubleshooting stage now before TDD fantactics throw stones - although admittedly I could have more under test), I work with 64 bit edition but figure this probably applicable at both x86/x64?
I'll start with one:
Ping Period (seconds) - increase from 90 to 3000 (or something somewhat higher) so you can if unfortunately need to a good bit of time whilst debugging or disable ping on local test machine.
Credit: http://blogs.msdn.com/johan/archive/2007/09/12/my-web-application-times-out-when-debugging-in-iis7.aspx
However I see over stuff such as:
Disable Overlapped Recycle & Recycling settings etc.. that I wonder if could increase performance or make debugging less friction
Question prompted by the annoyance that I've ran across a few recent debugging issues (not apparent in production) including a random, and tempormental error "An assembly with the same simple name blah-blah-lah-assembly-definiton has already been imported . Try removing one of the references or sign them to enable side-by-side." (iisreset resovles) and generally slow debugging attaching. The points and answers to this question need not help with the above (I believe it may be related to spark view engine as that where the stacktrace ends) but figure it worth mentioning incase someone has a direct suggestion *
quick tip: if you're experiencing slow response times (~1-1.5 sec) from browsers other than internet explorer (eg: firefox, chrome, safari) while running your mvc/ other web app on your local machine using win7/vista, it is due to dns resolution with ipv6.
firefox solution: disable ipv6 in about:config (boolean cfg 'network.dns.disableIPv6')
machine wide soft solution: uncomment the good old localhost address in the hosts file (%WINDIR%\System32\drivers\etc\hosts):
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
machine wide hard solution: disable ipv6 completely
credit goes to this blogpost: http://weblogs.asp.net/dwahlin/archive/2007/06/17/fixing-firefox-slowness-with-localhost-on-vista.aspx
Embarcadero guys just published a fresh article on similar topic for Delphi Prism (aka Delphi for .NET), so why not take a look on their suggestions?
http://edn.embarcadero.com/article/40108
From the experience i have working with asp.net mvc, i can tell that there are no special settings for IIS 7 or IIS 7.5 for working on asp.net mvc projects. It works fine in the default form, you just need to create a new website and point it to the folder that has the files for you application.
For debugger if you ask, you can simply put a breakpoint in the code and hit that breakpoint when you run the application from visual studio. But by default the application will use the development web server that fires up when you run a web application from visual studio. If you want to the application to run using the IIS installed on your system you will have to change the project settings. See here for a screen shot of how to do so
http://blogs.bootcampedu.com/blog/post/Debugging-aspnet-mvc-application-using-IIS.aspx
Additionally you can also use System.Diagnostics.Debugger.Break(); for putting a break point in the code.
If you only want to debug your application, I recommend to use the built-in development server of Visual Studio.
If you debugged the most of it or want to do that on IIS, I recommend you the Ctrl+Alt+P shortcut, which enables you to attach a debugger. Select w3wp.exe and you can debug with IIS.

Running Visual Studio in Parallels for mac - problem with debugging sites sitting in os x drive

I've installed parallels desktop on my MacBook to be able to run Visual Studio 2008 in a XP installation. Everything works great except when I decided to put my websites in my sites folder in the os x file system (Which by default automatically happens because the My Documents folder is mapped to the Mac's Documents folder, and I'd rather put my code there so that both OS's can easily access it.).
When trying to build or debug I get this error:
Failed to start monitoring changes to 'Z:\xxx...'
How do I get it so that I can get it to work under Parallels, from the shared drive?
Parallels uses network drives to simulate folders on OS X, and Windows can't monitor changes to network drives, so if you do this directly, it'll be broken.
If you want to keep them in sync though, use Live Mesh (http://www.mesh.com) and install it on both the host and guest. A little roundabout, but it'll make it so both copies are maintained (and Live Mesh is handy for other things too)
I recently flipped over to putting my source code onto my Mac volume, so I could use Time Machine to back it up and immediately got this same problem with my ASP.NET app. Other, procedural applications, built just fine, by the way.
I tried all sorts of things, including using Samba on the Mac side to share the directory, which led into the "too many BIOS commands" error described elsewhere. Unfortunately for me, the Registry hacks to fix that problem never worked for some reason.
I finally found another solution that avoids Samba and just uses the regular Parallels Shared Folders. It too is a Registry hack, but this one simply turns off file change monitoring for ASP.NET. It is a bit heavy-handed, but gets my builds to work again.
The reference for this change is here:
http://support.microsoft.com/kb/911272
The downside to this approach, I am finding, is that you need to be more deliberate about recompiling, or restarting the web server, as changes during development don't just magically appear anymore. I am still deciding whether that is a useful tradeoff.
UPDATE: After several days of this, development was just too difficult and, sadly, what I reverted to was keeping my source inside the Parallels virtual disk. To enable Time Machine backups and Spotlight searches, I used a lightweight MS utility called SyncToy to push stuff out of Parallels and out to my Mac drive several times a day. Despite the high hack factor, it is working well.
I know this isnt strictly a solution but VMware fusion is superior when it comes to shared drive space on a virtual machine. Its what i currently use and hasn't let me down thus far...
People always give me odd looks when they see visual studio on my mac :P
Try moving the project on to the VMs C drive. Its not an ideal situation, but you can access the VMs C drive from OS X.
I have a similar problem with a php site that uses an MS Access database (its a clients system). I have alias's that point to the php site on the VM so that I can still do all of my coding in OS X. To do this I created a network share on the VM and then connected to it from OS X. Once connected make the alias's. If the network drive is not open and you open a file in OS X it will try to reconnect. It means the VM will need to be running to get to the files, but this isn't normally a problem since the VM is hosting the site anyways.
.NET has funny issues trying to debug the objects on a network drive.
make sure that you have full trust on your local network between your Mac and XP install.
Check out: http://msdn.microsoft.com/en-us/library/aa302361.aspx
If at the end of that research, I"m afraid you will have to look into the option of keeping it on the VMDisk and moving it when you need it.
I see a similar problem on my machine connected to the windows domain. My documents is mapped to a network share and I can't debug|run|etc. I had to eventually move to my local disk for debugging.
I definately recommend Live Mesh as a way to keep directories in sync. Just keep the VM's directory in sync with the Mac's directory.
Or use SVN to hold copies in both machines and do commit/update as appropriate. That way you get versioning, history and if your project grows bigger, you can share with other devs.
I know dropbox also has history and sharing, but not check in/check out/conflicts and all the other advantages of a real source control.
Oh, if you have money you can also go for TFS. I would but it is just too expensive :)

Resources