Thursday

Node Grunt error enoent stat roaming npm


If you are working on protractor or any similar application, the prerequisite is to install node and grunt. Installing node is a child's play but if you are trying to install grunt

npm install -g grunt-cli

It bombs and says  Error: ENOENT, stat 'C:\Users\Ady\AppData\Roaming\npm'

Solution: Manually creating a folder named 'npm' in the path that it specifies , in this case C:\Users\Ady\AppData\Roaming\npm

Reason: a bug in latest NodeJS for Windows installable

Tip: Run the command prompt as administrator.

Wednesday

PhantomJS Selenium Webdriver Java - setup and Error trying to find element with xpath



If you have a Selenium Webdriver framework that is working at its best!
All you now need is  a headless browser like PhantomJS to test your web applications that make the functional tests faster. (According to their website PhantomJS is “a headless WebKit with JavaScript API.” Webkit is the layout engine used by a few browsers, such as Chrome and Safari. So PhantomJS is a browser, but a headless one.)

Here are simple steps to add this capability in your selenium scripts:


  1. Download PhantomJS and extract the package. or windows its an exe file and for Mac its just a zip package you will need to extract. 
  2. Extract the phantomjs-1.9.x-windows.zip folder and locate phantomjs.exe file. 
  3. Copy this file to a common location where the framework libs are stored.(In my case I used the same space as ChromeDriver and IEDriver) 
  4. Add the following imports to your code:
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.phantomjs.PhantomJSDriverService;


  1. In the place where you initialize WebDriver driver = new FirefoxDriver

  caps.setJavascriptEnabled(true); caps.setCapability(“takesScreenshot”, true);        caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,”C:\\Users\\\\Desktop\\Automation\\JavaLib\\PhantomJS\\phantomjs-1.9.2-windows\\phantomjs.exe”);   WebDriver driver = new PhantomJSDriver(caps);

  1. Continue coding as before with screenshots :) 
  driver.navigate().to("http://www.xyz.com");
  driver.manage().window().setSize( new Dimension( 1124, 850 ) );
  File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);     FileUtils.copyFile(scrFile, new File(“C:\\<savePath>\\iamnotadumbass+”.png”));

Note:  An issue I faced and was confused before I realized that this error message "Error trying to find element with xpath" does not really mean that but instead you need to be using http and not a https protocol for your webpage.

Alternative solution: 
The problem is most likely due to SSL certificate errors. If you start phantomjs with the --ignore-ssl-errors=yes option
phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions]
If that does not work try:
1. change user-agent
2. ssl-protocol that worked was tlsv1 or --ssl-protocol=any

Happy headless testing!

Monday

Schedule a Java ANT program on windows



This is the easiest way to schedule a ANT build.xml script that you want to Run on any machine

  1. Make sure you can navigate to the path where you have the build.xml stored and run the ant command from command prompt
  2. Once confirmed that you are able to run the script from the command line
  3. Create a .bat file with just one word ant in it. This does not do any exception handling
  4. Open the control panel -> System and Security -> Power Options  and make sure that the computer never sleeps option is set (you need admin rights)
  5. Open the control panel -> System and Security -> Administrative Tools -> Task Scheduler
  6. Create a new task and navigate to the path of the .bat file in the Actions Tab under start a program
  7. Make sure the "Start In (Optional)" field has the absolute path to the file (without quotes)
  8. The final change is assigning the "Full Control" permission explicitly to .bat file for the account running the task.

Note:
  • Make sure that the task is running as an account that has explicit "Full access" permissions to all these things: The .bat file itself, the folder containing the .bat file, and the target files/folders that are affected by the .bat script. Inherited permissions didn't seem to work for me.
  • Make sure that the account running the task is a member of the local "administrators" group for this machine
  • Make sure that the task is set to "run whether logged on or not"
  • The Task should run successfully with expected output when you right-click on the task and select "run" If it does that then it will run successfully when you are logged off.

Friday

Performance testing with Selenium Webdriver - Navigation Timing API




In continuation to my previous post on performance testing with Selenium Webdriver , I found the "Navigation Timing API" the best way as it has loads of parameters that we can slice and dice the way we want to get different performance parameters like:

"Total Time:"+(loadEventEnd - navigationStart)/1000 + " seconds"+ "

"Server Render Time: "+ (responseEnd - requestStart) + " milliseconds"

"User Experience: "+ (domComplete - requestStart) + " milliseconds"

"Network:"+ (connectEnd - navigationStart)/1000 + " seconds"

"Server:"+ (responseEnd - requestStart)/1000 + " seconds"

"Browser:"+ (loadEventEnd - domLoading)/1000 + " seconds"

The properties you can play with are:


























The meaning of these events is described in Microsoft's performance.timing documentation and more formally in the W3C Recommendation.

Thursday

Performance Testing using Selenium Webdriver



Yes we know that Selenium Webdriver is a functional testing tool and is not a recommended option to do performance! But then there are times that you want to just do a quick performance check and find the bottlenecks in your application, here is how:

The solutions here are organised based on the complexity and detail you want to achieve:

Solution 1:  Measuring performance using a Timer in Selenium WebDriver

We can use the the StopWatch class for measuring the time taken for the page to load or any inbuilt date time calendar feature:


StopWatch pageLoad = new StopWatch();
pageLoad.start();
//Perform your test
pageLoad.stop();
System.out.println("Total Page Load Time: " + pageLoad.getTime() + "milliseconds");

Or

Calendar cal = Calendar.getInstance();
Date d1 = cal.getTime();
//Perform your test
Calendar cal2 = Calendar.getInstance();
Date d2 = cal2.getTime();
long diff = d2.getTime() - d1.getTime();
long diffSeconds = diff / 1000 % 60;  
long diffMinutes = diff / (60 * 1000) % 60;   
System.out.println("Execution Time:",diffMinutes+" minute and "+diffSeconds+"seconds"););

Solution 2:  Measuring performance with the Navigation Timing API

JavascriptExecutor js = (JavascriptExecutor) driver;
long navigationStart = (Long) js.executeScript("return window.performance.timing.navigationStart;");
//Perform your test
long loadEventEnd = (Long) js.executeScript("return window.performance.timing.loadEventEnd;");
System.out.println("Page Load Time is " + (loadEventEnd - navigationStart)/1000 + " seconds.");

Solution 3:  Measuring performance with JMeter
http://seleniummaster.com/sitecontent/index.php/performance-test-menu/selenium-load-test-menu

Solution 4:  Measuring performance with Firebug's Net panel
http://www.softwareishard.com/blog/firebug/automate-page-load-performance-testing-with-firebug-and-selenium/


Hope that helps someone playing with Selenium WebDriver and trying to achieve some basic performance testing!

Tuesday

Happy World Tester's Day!

Now this is a day that I love, though I was introduced to this just three years back and if you are still wondering what is it all about:


On September, 9 1945 the scientists of the Harvard University while testing the computer Mark II Aiken Relay Calculator had found a moth which got stuck between the contacts of the electromechanical relay. 

The work they performed required some description, and the word had been found – «debugging» (literally: disposal of an insect) – and now it is used to describe the process of identifying and eliminating bugs which cause a computer to malfunction. The removed insect was pasted into the computer log with the entry: “First actual case of bug being found”, and was then transferred to the computer museum.

Now that you know, Happy Tester’s day !

Monday

SeeTest Cheatsheet for Mobile test automation

Here is the first of its kind a cheat sheet for SeeTest mobile test automation:






P.S: Click on the image to download a larger copy. You can also email me for an excel version for easier navigation!

Happy Mobile testing!

Friday

Remotely access a Mac machine from windows machine



There are many tools that allow you to remotely log-in either between two Windows / two MAC machines. There are five tools that I evaluated while choosing which one is the best to
remotely access apple Mac OS X from Windows. 

  1. TeamViewer
  2. LogMeIn
  3. RealVNC
  4. Vine Server
  5. Remote Management
The best tool that I thought when it comes to automation is the free version of LogMeIn. The reason being the refresh rate and the connectivity. You can write a small script that can even help you schedule tests on the remote machine!

  • LogMeIn is Free 
  • Web interface or the Firefox plugin. 
  • Easy steps 
    • First you will need to create a free account
    • Login from the Mac computer and click the Add Computer button to download the LogMeIn Installer. 
    • After installation, you can access that computer from any other computer by logging in to LogMeIn.

Thursday

Modify the IP headers on the iPhone / Bypass or change the ip on any device

Problem: If we need to test an application which is outside the network or with a different IP address how do we do that? we need to be able to use a proxy server that bypasses or replaces some properties that can be then used to modify the way the application is accessed.


Solution:
Here is an example of how to do that on an iPhone (You can do this for any device) :

  1. Go to settings in iPhone and modify the manual IP address. Give it the same IP address as that of the local machine where the proxy server would run and select a valid port : say 8080
  2. To set the IP headers or proxy download the Burp Free edition from here: http://portswigger.net/burp/download.HTML
  3. Go to the Intercept tab and make sure it is off.
  4. Go to Options tab and edit the Proxy listeners to local ip of the machine:
  5. Scroll down to Match and Replace Pick a Request header not in use and modify that:
    In our case “Client-Version” to
  6. Now check the HTTP history tab to confirm that the header is replaced while surfing applications.

Monday

How do I get my Nexus 7 to show up in the adb devices list ?




Problem:
  • Nexus 7 that I'm trying to connect to Windows computer for automation over adb
  • No device driver for nexus 7 ?
What did not work:
  • I did click on the build number 7 times to get the developer options enabled
  • Tried connecting both as a Media device (MTP) and as a Camera (PTP). ("Connected as a media device" up at the top left corner, de-selecting Media Device (MTP) and then checking Camera (PTP).)
  • downloaded this usb driver: http://dlcdnet.asus.com/pub/ASUS/EeePAD/nexus7/usb_driver_r06_windows.zip
  • Go to the device manager , right click the nexus device and choose properties, choose "hardware" and then choose update your driver , choose manualy and pick the folder you opend the zip file to and press apply.
What worked for me:

The universal adb driver installer worked for me. Download the universal driver exe Run with the device connected and it will give you an option to install. http://adbdriver.com/
Install that and you will now see the option on your tablet to connect to the computer :)

Update: What worked on Windows 8.1


If the device is listed in Device Manager as Other devices -> Android but reports an error code 28:
  • Google USB Driver didn't work for me. You could try your corresponding OEM USB Drivers, but in my case my device is not listed there.
  • So, install the latest Samsung drivers: SAMSUNG USB Driver v1.5.33.0
  • Restart the computer (very important)
  • Go to Device Manager, find the Android device, and select Update Driver Software.
  • Select Browse my computer for driver software
  • Select Let me pick from a list of device drivers on my computer
  • Select ADB Interface from the list
  • Select SAMSUNG Android ADB Interface (this is a signed driver). If you get a warning, select Yes to continue.
  • Done!

Happy Android Automation!

Funny way to enable developer options on android



Problem : Toggle on the "USB Debugging" in the "Developer Options" area of Settings in an android device
This is a prerequisite to perform automation.

Solution:
If you do not see "Developer Options"
  1. Go into "About device" in Settings 
  2. Tap on the "Build number" entry seven times, which will unlock "Developer Options".

So it's that simple tapping the build number will make you a developer :P