CasperJS + PhantomJS on Mac - First Test

1. Installation of CasperJS : open the Terminal and fire up these commands
$ brew update
$ brew install casperjs --devel

To test if the installation of casperjs was successful, type on terminal
$ which casperjs

you should get - /usr/local/bin/casperjs which means everything is fine
2. Install PhantomJS : open the terminal and fire up these commands
$ brew install node

This will install node. After which you can use the node/npm without using sudo
$ npm install -g phantomjs

To test if the installation of phantoms was successful, type on terminal
$ which phantomjs

you should get - /usr/local/bin/phantomjs which means everything is fine

Now you are all set to write your first test. Make sure you have BBEDIT installed ( best Code editor , i have seen ). Here, is a sample first test script for you

Remember to run this command in terminal, this will take care of your blank screenshots and https:// requests if any
$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any caspertest.js

Data driven tests using Xunit, Excel & Selenium

So, what is xUnit.net? xUnit.net is a unit testing tool for the .NET framework. For example, C# and VB.net. It was created by the original inventor of the NUnit testing framework and seeks to address some of the shortcomings of the NUnit framework in use. It's a free and open source framework, and it's licensed under the Apache Version 2 license.When we create tests with xUnit.net, we can run them with the Visual Studio 2012/2013 Test Runner, we can run them in Resharper, in CodeRush with TestDriven.NET, and we can also execute them from the command line. For updates on xUnit, you can follow xunit@jamesnewkirk or bradwilson on Twitter. And the home of the project is at xunit.codeplex.com.

So, with that background lets get started.

Create a class library project
Let's start by creating a class library project, targeting .NET 4.5 (or later). Open Visual Studio, and choose File > New > Project:

2. Extract and add the 2 dll’s as reference to your class project. Along with that you can also add the Selenium Webdriver if you have already downloaded or you can use the nuget package references for it.

image

3. Now you can go ahead and write your normal Selenium cases in the Xunit framework using the fixtures of Xunit , using either [Theory] or [Fact] .You can read more about this here

4. So, a simple usercase of gmail login is as follow

4. Now, if we want to make this test as data driven using Excel, we start off with first creating an excel data sheet. Let’s call it as SampleData.xls .

image

5. Create a named range in the excel sheet for the data. You can create the same by

  •    Highlight the desired range of cells in the worksheet and right click on it. Choose Define Name
  •   Type the desired name for that range in the name box, such as TestData

6. Once the named range is defined, we can save that as .xls and not .xlsx ( just ensure that it’s 2003 xls , for some reason, I never got it to work with .xlsx) in the solution folder. Also ensure that the properties of the excel is set to “copy always”

image

7. Now we need to add a new fixture below the [Theory] , called as [ExcelData] . The query statement implies that we select all data from the named range TestData. So the above code can be changed to data driven as below

8. Now, you can run these tests either using the Visual studio runner or the Resharper. There is another simple way to run the test. If you go to your Xunit folder where you downloaded the binaries from, you can see an exe – “xunit.gui.clr4.x86.exe” . You can launch this app, and point it to your dll from your debug folder and voila , the tests will run. ( Just remember to add the path to your environment variable)

9. In case you run into an error related to JetOLEDB,

Just change the Property of the project into x86 format

Project---> Properties--->Build--->Target Framework---> x86

TIPS:

Deleting a named range

  • Open Microsoft Excel, then click "File" and open the document containing the named range you want to delete.
  • Click the "Formulas" tab and click "Name Manager" in the Defined Names group. A window opens that contains a list of all the named ranges in the document.
  • Click the name you want to delete. If you want to delete multiple names in a contiguous group, press the "Shift" key while clicking each name. For names in a non-contiguous group, press "Ctrl" and click each name you want to delete.
  • Click "Delete," then confirm the deletion by clicking "OK."

Change a Named Range

  • Launch Microsoft Excel and open the file containing the name you want to replace.
  • Click the "Formulas" tab. Click "Name in Manager" under the Defined Names heading.
  • Click the name you want to replace, then click "Edit" in the Name Manager box.
  • Enter a new name for the range in the Name box. Change the reference for the name in the Refers To box. Click "OK."
  • Change the formula, constant or cell the name represents in the Refers To field in the Name Manager box.
  • Click "Commit" to accept the changes.

Cross Browser Playback in CodedUI

In effect , Cross Browser Playback is only useful to actually check UI differences between the different browsers. So the popular belief of replaying all the tests for testing the cross browser is just a myth. To improve your effectiveness, you may want to target specific tests at specific known UI problems in your app.   
Cross Browser Playback enables you to validate if your app is usable from different browsers. It also makes sense to create a few core end 2 end scenario’s you want to validate before you ship like purchasing an item from an online shop. You can also focus on critical business function that would seriously impact your business when stuff breaks. Thereby making playback resilient tests is crucial here so just ensure that your controls are  easy to identify, e.g. by ID across browsers

image

So, how do you get the ability to run the UI web tests you created in multiple browsers? First you need to have Visual Studio 2012 Update 1 or higher. So, this will not work with Visual Studio 2010 if you have not yet upgraded yet to the latest version of Visual Studio. The next thing you need to do is you need to go to the Visual Studio Gallery and there search for cross browser. Then you will find the Selenium components for Coded UI Cross Browser Testing. You can then download the installer, and then you need to install this package on every machine you want to play back the tests. So, when you have multiple test machines that are part of a test lab environment, for example in Team Foundation Server Lab Management, then you need to go to all these machines and install this package. You can also search for this package from the Visual Studio IDE. There you can go to the Tools menu, and there you go to the Extensions and Update menu. Here you can search the Visual Studio Gallery feed and then install straight from Visual Studio. Another thing of course that you need to install are the browsers Firefox and Chrome in order to play back on those browsers. One last thing to note is rather important, and that is that you can only record with Internet Explorer. So, if you choose to use the UI map files that we've discussed in the previous modules, then you can only record using Internet Explorer. You can still play back those recordings using the other browsers, but the recording itself needs to be done from IE.

Understanding cross Browser Playback
image
Look at the architecture of CodedUI. To understand how cross browser playback works we have to look at the bottom layer of this architectural diagram again. We know that CodedUI can work for any technology we'd like as long as there's a driver that can plug into the technology manager layer, and then we need to be able to select the right driver to run the test. Now, for cross browser playback what Microsoft did is write a switch in the web driver that can switch between the two technologies for playback. It still uses the standard implementation leveraging the MSHTML/DOM of Internet Explorer, but they now added the option to switch to a different engine called Selenium. Selenium is a technology solidly designed for browser testing. Selenium has the ability to play back scripts on different browsers for a few years now, and rather than building a competing technology, Microsoft adapted their engine to use the Selenium web driver to run the tests. You might ask yourself but what about Safari? I don't see that browser here in the playback browser symbols. Unfortunately that's true. There's no web driver in Selenium as well for supporting Safari, so that means that we can only play back on other WebKit-based browsers like Firefox and Chrome. This can give at least some confidence that it might work in the Apple WebKit-based browser, but unfortunately Google forked their implementation of WebKit for their browser so it becomes more likely each day that you will not find issues that might occur in Safari-based browsers because the browsers don't use theexact same rendering engine anymore.

How to Switch Browser on Playback
So, now we know what to install and how it works, but what do we need to do in our code to make this all work? The good news is almost nothing. The fact that Microsoft provides an implementation of their web driver in CodedUI that can switch technologies for playback makes switching browsers a breeze. The key element of making the switch is setting the current browser property of the BrowserWindow class. So, what we need to do is we need to specify the browser we want to use for playback. If we don't specify anything or IE, then this means it will be played back in Internet Explorer. If we set the current browser property to contain a text string Chrome before we call BrowserWindow.Launch, it will launch the Selenium Chrome web driver to run the test. If you specify the string Firefox, then it will use the default Selenium implementation that plays back on Firefox. One thing we of course also need to do is install the correct browsers on the machine, so we do need to install Google Chrome, Firefox, or Internet Explorer on the machine that runs the test.


Unsupported Features & Known Issues
So, there are a few caveats to look out for when using cross browser playback. Of course the thing we already discussed, we cannot play back on Safari-based browsers, and that's a problem we cannot fix other than by trying some of the key scenarios by hand and validating every now and then if you see differences in the browser behavior and watch out for those cases. The other problem that you might encounter is that search fails when it normally dependent on a filter to find the right control. A search is executed first based on the search properties, and when multiple controls are returned then a filter is applied to find the control in a set of returned controls. The cross browser implementation does not actually use the filter other than TagInstance, meaning that if your search relies on a filter on some property other than TagInstance of a control then the search will fail. To solve this problem you need to move the filter properties to the search properties. Since all the search properties are translated into a Selenium search, you will see that the search will then succeed. It's always best to try and use search as much as possible and try to keep away from filtering. But when using CodedUI record and playback, the filter properties are used more often, so therefore chances are that this will happen to you when you use record and playback, and it is less likely to happen when you hand code using the object model. Since search in Selenium is done in a different way, it is possible that you can get an error message Error Element does not exist in cache or that your search fails when an element appears delayed on the screen because JavaScript needs to complete on an AJAX call before it shows on the screen. In these cases there is a simple solution to fix this problem. The solution is to use the WaitForControlExist API and before we access any property on the control we can use the WaitForControlExist API to block the call until the control becomes available.

Data Driven tests in Coded UI using MSTest

Microsoft MSTest supports data driven tests where you can specify a data source and the test method will be executed for each row in the set , either in Sequential or Random mode based on your choice and need.
Since CodedUI is based on MSTest, we can build data driven UI tests as well. This enables interesting options to specify all data entry in a data source and not directly in your test method. This also enables functional testers to specify the test scenarios

Now, Different data sources can be used to drive the UITests. Some of them are
Comma Separated files (CSV)

  • XML
  • Excel (xls, xlsx)
  • Test Case from Microsoft Test Manager (MTM)
  • SQL Server

You can easily specify the data source as part of the test method declaration. Refer previous post for more clarity.

The Data Source attribute defines the data connection you want to use

Now, in your test method you can access the data row via the TestContext

For CSV,

The |DataDirectory| will resolve to the correct location at test as long as you deploy the csv file with your test. Data#csv is the table name you have to use with CSV


For SQL,

For XML,

For MTM,

image

FOr Excel,

image
If you have the actual connection available, so you can use ADO.NET to access additional sheets of data. E.g. let first sheet be the index into subsequent data sets or Query on named ranges

 

Deploying the required resources
Now, the question is how can you deploy your excel sheet with your tests? or how can you deploy assets required during the test run in general?
The answer lies within MSTest itself. MSTest has the option to specify deployment items. For this, you need to do the below things

  • Need to Set deploy to true in test settings file
  • Annotate the test class or method with DeploymentItem attribute

Add the assets to your build deployment

  • Add a folder named assets to your solution
  • Add files you need like excel sheets or pictures and set them to copy to output

Refer the DeploymentItem attribute to the assets folder

  • Use test context Deployment location to refer to the deployed item you need

Data driven tests using MSTest & Selenium

There are a lot of literature including the ones on Microsoft KB’s which talks about how we can make our tests data driven. These employ the use of additional app.config file. After many headaches, I have figured out a way to accomplish the same without the use of app.config.

Getting ready

1. Create a new C# unit test project in Microsoft Visual Studio 2012 and name it SeleniumDataDrivenTest

2. Add a reference to the WebDriver .NET binding

3. Create a excel sheet from where you want to read the data from. Let’s call that data sheet as Data.xlsx

You can parameterize a test in MSTEST by adding the Excel spreadsheet to deployment items of the test project, using the following steps:

1. Click on solution and choose to add a Test Setting and continue as shown in the following screenshot:

image

image

2. The Test Settings dialog will appear. We need to add the test data file by clicking the Add File button in the Deployment section, as shown in the following screenshot:

image

3. Once you add the file to the Deployment section, it will appear in the list, as shown in the following screenshot: Let's ensure that we create an excel sheet from where you want to read the data and call it as as Data.xlsx.

image

image

4. In the solution explorer, use the Show all files and your file "Data.xlsx" should now show up. Once it does , right click on it and choose include in project. Your solution show now resemble something like the screenshot below

image

5. Now right click on the "Data.xlsx" file and choose to modify it's properties. Set the Build Action to Content and Copy to output directory as either to "Copy always" or "Copy if newer". I always tend to leave it as "Copy always"

image

6. Now copy the below code to the class

How it works :

When we add the DataSource attribute to a test in MSTEST, it provides data source-specific information for data-driven testing to the framework.

image

It reads the test data from the source. In this example, the source is an Excel spreadsheet. The framework internally creates a DataTable object to store the values from the source.The TestContext test method provides a collection of data rows for parameterization. We can access a field by specifying its name, as follows:

image
With the DataSource attribute, we can specify the connection string or a configuration file to read data from a variety of sources including CSV File, Excel spreadsheets, XML files,or databases.

Powershell script to add header information into c# code

Sometime back, I had to check-in a huge automation framework into the TFS repository. I realized that I had not added headers to any cs files. So, I quickly cooked up a powershell script to get this done for me. The code is self explanatory and is as below

Powershell scripts for downloading file & refreshing data connections

One of the requirement I had was to download a certain file from the sharepoint on a daily basis and take a snapshot of the same for future reference. The drawback with Sharepoint is that we can download the file, but unless someone opens the file , refreshes all the connections and should perform the save, only then it will be updated. I achieved this with powershell and another tool available here – ExcelRefresh. You can use the code below to do that activity.

My setup was to place the ExcelRefresh.exe in the same folder where the downloads were being dumped.

Writing your first test using Casperjs

Casperjs is a wonderful open source navigation, scripting and testing utility written in JS which uses PhantomJS webkit , which is a headless browser. It simplifies the process of defining a full navigation scenario and provides some high level methods for doing tasks such as – entering text, clicking, logging, navigation and logging events.

I had to spend some days to get my first test case running, so here I am making my notes which will benefit me in the longer run. ( In case you have more info, please leave a comment)

1. Download and set your environment paths for casperjs and phantomjs ( refer – previous post)

2. Create a folder say C:\JSplayground ( in my case) which will house your casperjs cases.

3. You can either use VS to write your new casperjs script or even a simple tool notepad++ will suffice.

4. Below is the code, I used, which you can also use to get your first case running. It’s pretty straight forward thing. You can copy the code and create a file with extension .js . In my case – sampletest.js

 

5. From the above code, If you have not figured out already, setting the capturePage as true or false drops the screen shot of the application under test in the same folder as your .js file. Ensure that the casper.userAgent is set to the same , as I was searching for long since some websites render and open differently for different browsers.

6. Once you have created your .js file, you can run now this script from your location by using the below command

 

7. I have given the option of using –ignore-ssl-errors=yes –ssl-protocol=any  so that even if your url is https:// your tests will run. BTB, Phantomjs had really bad support for SSL until 2.0 release. ( unfortunately I am on a newer version of Phantomjs and Casperjs is not equipped to handle 2.0. However, thanks to rdpanek , he has released a fix for CasperJS bootstrap/ Phantomjs 2.0 fix)

screenshot_Wed_Feb_18_10.34.54

Phantomjs & Casperjs – Installation Simplified

To run Phantomjs & Casperjs on your system, here is the installation steps you need to follow. Though these are pretty simple ones, but the lack of proper documentation can actually send you on a leather hunt just to get your first case running. So here it is simplified.

1. Download Phantomjs from here.

2. Unzip the entire package to say c:\phantomjs . Ensure that the phantomjs.exe is copied from the subfolder bin to man folder. So your final folder should look somewhat like that.

screenshot_Tue_Feb_17_21.52.36

3. Now head start –> right click my computer, choose properties –> Advanced system properties – > select advanced tab and click on Environment Variables.  Append ;C:\phantomjs to your PATH environment variable. Feel free to modify your installation and update the PATH settings to reflect the same

screenshot_Tue_Feb_17_21.56.04screenshot_Tue_Feb_17_21.58.31

4. Now download Casperjs from their home page

5. Extract the contents to c:\casperjs

6. Ensure you add this PATH into your environment as shown above.

7. Restart system and try these two commands to make sure the PATHs are properly set.

phantomjsscreenshot_Tue_Feb_17_22.06.07

You are now all set!

VB script code to keep the system alive and prevent locking

Use the following code: (Save it as .vbs and execute, it will run for ever). Kill the wscript from the task manager when u want to stop.


----
You can replace the NUMLOCK with either CAPSLOCK if it creates issues with your UI testing

Create Multiple app.config files and run them with pre build events & msbuild

 

Today we were stumped with having different config files for automation for different environments like QA, Daily runs, BDT etc . While there are various ways, we could have resolved this, each of the methods we thought had one or the other challenge as we needed a single simple solution so that we could service 20 products line.

Also, making changes to the code base did not make sense. So here is how we achieved it

1.  Go to the solution – > right click choose configuration manager. In that screen use the drop down for active solution configuration and choose new. You will be prompted with the new solution configuration as shown below. We added DailyRun as our name.

image

2. Now go ahead and create any number of configuration files you want. Here in our case, we have BDT, DailyRun and Release1 as the configurations for different environment.

(side note : in our solution we had set the original app.config as a content and property always copy. The other configs were left out as it is. As app.config is the main file and that is the one which does all the hard work)

image

3.  Let's create a batch file called "copyalways.bat" and here's the contents:

Put this copyalways.bat file in the root of your project. Basically this batch file will copy a file over another if the files don't match.

4. Create a Pre-build Event. Right-click on your Project and select Properties. Click Build Events and in the "Pre-build event command line" and enter this value:




5. Now if you build, you'll see in the Build Output the batch file being run and the files being copied. Because it's a Pre-Build Event it'll be seen in both the Build Output in Visual Studio .NET.

 

And there you go. The connection string in the web.config now contains deployment-specific configuration data.

You can add only the parameter part to your build definition now. This will help you run the same solution with different config files.



(Note: we noticed that once the newer app.config is copied , the file was becoming read-only and was not taking in the next build config. The way to solve it would be to make it non read only within the code itself. I will post that code soon).

Done. Here is the complete code of the bat file

Dashboard using ElasticSearch, Logstash & Kibana - 1

All set ? I will try my best to list down the exact steps followed by me to get the ELK stack working on windows. I have tried to get in as much details as possible , special thanks to my co-worker – Kiran, for helping me with this research

This guide was installed successfully on  - Windows 7 Enterprise

Let’s get started

1. Dowload ElasticSearch , Logstash and Kibana from here

2. Create folders in your local drive say c:\Elastic and extract all the folders. So, after it is done, here is how it looks

c:\Elastic\elasticsearch

c:\Elastic\logstash

c:\Elastic\Kibana

Optionally, you can create a new folder say – elasticlogs , which will house the log files, incase you want to dump it there

c:\Elastic\elasticlogs

In the Elasticsearch\bin folder , edit the elasticsearch.yml to include  -

http.cors.enabled: true

Create a logstash config file with


                input {
                file {
                  type => "XMLLogs"
                  path => ["C:/ElasticLogs/*.*","//networkpath/*.*"]
                }
                }
                output {
                 stdout {codec => rubydebug }
                elasticsearch {
                   host => "localhost"
                    protocol => "http"
                    }
                }

3. Download  and install the latest version of Java JDK and install it depending on your OS architecture

4. Set your Java path , to do this

Right click on the My Computer icon on your desktop and select properties

Click the Advanced Tab

Click the Environment Variables button

Under System Variable, click New

Set Java Home Step 2Bullet4.jpg

Enter the variable name as JAVA_HOME

Set Java Home Step 2Bullet5.jpg

Enter the variable value as the install path "C:\Program Files\Java\jdk1.8.0_06" (update your java version accordingly

Click Ok

Click apply changes

5. Install IIS

  1. First, go to Control Panel, and then click on Programs. You’ll see a link for “Turn Windows features on or off”
  2. If you expand the Internet Information Services tree node, you can see that there are a lot of options beneath it. You will probably want to explore these options, because even if you click on IIS, some of the necessary options for doing development aren’t checked.
  3. Once you’ve gone ahead and checked the items you want, and clicked OK, you’ll see this dialog for a while….
  4. Now when you navigate in your browser to localhost, you’ll see the new default page…

6. Open IIS Manager, by going to command prompt and using “inetmgr”  IIS manager will open, now stop the "Default Web Site"

iisstop

7. Create a new website for Kibana as shown below
Right click on "sites" in the left part of IIS Manager and click "Add Website" . In the end it should look something like this

IISwebsiteadd

You can add mime types as below if your IIS version is older

".": application/octet-stream
".json": text/html

8. Start elasticsearch by hitting this in command prompt C:\Elastic\elasticsearch\bin>elasticsearch

9. Check if your elastic search is working by pointing your browser to localhost:9200

You should get something like this.

elasticsearchreply

10. Now reboot your server so you can test that everything is automatically starting on boot.

kib1

Congrats you have installed it!

 

Some Tips:

To clear elasticsearch cache
1. Install curl - http://www.confusedbycode.com/curl/
2    run from cmd - curl -XDELETE "http://localhost:9200/_all"

Starting logstash
logstash.bat agent -f logstash.conf
 
To check if the logstash config file is correct with parameters
  logstash.bat agent -f logstash.conf --configte

Setting up the Logstash and ElasticSearch to run as an automatic service.

1.  Start elasticsearch and put it on autostart
Open a console and go to "c:\Elastic\elasticsearch\bin\" & type the following command:

service install

You should get service has installed

Now type – service manager and  something similar to below should appear

serv

 

You have to change on the tab the "Startup type" from Manual to Automatic and then press Apply this should make Elasticsearch start automatically on server boot.
This window contains some more options such as how much memory Elasticsearch will use you can find this on the "Java" tab I would suggest to make this fitting for your server if you have a servers that will handle a huge amount of logs I would increase the "Maximum Memory Pool: 1024" at least to a higher amount.
Before you close the window make sure to press "Start" so it actually will run right now

This is everything to start ElasticSearch automatically on boot to test that it is working open a browser and go to the url you used in IIS  or go to: //127.0.0.1:9200/
If you see a json string something like what you saw in step 9  picture then it means your Elasticsearch is running

2. Create a Logstash startup bat file

A “run.bat" should simply contain this line -

logstash.bat agent –f  logstash.conf

Now place your "run.bat" in the folder: C:\Elastic\logstash\bin

3. Start Logstash & Autostart it
For this step we need another small program to create a proper windows service so please go ahead and download "NSSM" (the Non-Sucking Service Manager)

Once you have the zip file simply unzip it and copy the file from the unzipped folder you now have: "nssm-2.24\win64" (nssm.exe) to "C:\Elastic\logstash\bin" so it should result in you having "C:\Elastic\logstash\bin\nssm.exe".
Now open a Command Prompt and type:

cd c:\Elastic\lostash\bin

nssm install logstash

Ensure you have the details filled as below

ser1

ser2

Also make sure that "Startup type" is on Automatic.

Now the following step is additional but recommended if you are 100% going to use Elasticsearch, click on the "Dependencies" tab and add the following: elasticsearch-service-x64

ser3

The reason for this step is that Logstash can do difficult if you have a Elasticsearch output but it is not actually running.
Now this is all so press on the "Install service" button to finish setting up a service for Logstash.

[​IMG]

Now, you actually can stop and start Logstash or Elasticsearch, easily from  "services.msc" as they are now windows services.

Thread.Sleep or Wait or FluentWait

Instead of sleep

public void clickOntaskType() {

getDriver().findElement(By.id("tasktypelink")).click();

sleep(500);

}

Prefer this fluentWait

public void clickOntaskType() {

getDriver().findElement(By.id("tasktypelink")).click();

SeleniumUtil.fluentWait(By.name("handle"), getDriver());

}

It’s more robust, deterministic, in case of element not found… the exception will be clearer.

Another alternative is

(new WebDriverWait(driver, 30)).until(new ExpectedCondition() {

public Boolean apply(WebDriver d) {

return d.getTitle().toLowerCase().startsWith("Awesome Tester");

Locating UI Elements–which to use

To locate an element we can use

the element’s ID

the element’s name attribute

an XPath statement

by a links text

document object model (DOM)

In practice, you will discover

id and name are often the easiest and sure way.

xpath are often brittle. for example you have 3 tables displayed but sometimes there are no data and the table isn’t rendered, your xpath locating the second table will not always return the intented one.

css are the way to go in conjunction of id and name !

locating links in an internationalized application is sometimes hard… try to use partial href.

Coded UI with Action Based Test Automation

A good video which gives a great overview of using Coded UI along with Action based test automation.

Automated JS testing - 2

Now that we are here - Lets look at some interchangeable frameworks for JS testing and also see how we can translate the unit testing to an end to end testing

Example of JS unit testing framework - Used to test jQuery, JQuery UI and jQuery Mobile . QUnit can be used easily and also it can be used to test any generic js code itself . A Sample test is written below. You can use the cookbook to enhance your knowledge further 

test(“a test example”, function(){

ok( true, “this test passes”);

var value = “hello"

equal (value, “hello”, “We expect value to be hello”);

});

Automated Web Testing using Java Script - 1

I think, i have used this way to often and pleasantly surprised when i hear ppl mention - What? You can use JS for automation? Some even think i am crazy. But that’s ok. What purpose does it solve for me anyways!

Here, i intend to start a series of my experience and rants on using JS for automation . Before that, for the benefit of folks, let me list why JS for Testing ? 

  • It is Free 
  • It is open source
  • It is modular
  • It has an active and vibrant community
  • If the client and servers use JS - why not tests?

Append a text file in selenium

Here is a little code I wrote for appending a text file in selenium

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Pattern;

public class WriteTextFile extends SeleneseTestCase {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
        selenium.start();
    }

    @Test
    public void testUntitled() throws Exception {
        selenium.open("www.google.com");
        String filepath = "D:/FindMeHere2.txt" ;
        FileWriter somenewfile = CreateTxtFile(filepath);
       
        AppendTextToFile(filepath, "here is how i would append the text");
       
    }

/*    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }*/
   
        public FileWriter CreateTxtFile(String fpath) throws IOException {
        System.out.println("Inside the Create Text File method :::: ");
        //String fpath = "d:/mynewtextfile.txt";
        FileWriter mynewfile = new FileWriter(fpath, false);
        //FileOutputStream fout = new FileOutputStream(fpath);
        mynewfile.write("This is a new text file , that i wrote  into ");
        mynewfile.close();
        return mynewfile ;
       
    }
       
        public void AppendTextToFile(String filepath, String testtext) throws IOException {
            System.out.println("Inside the Append Text  to File method :::: ");
        //FileOutputStream fout = new FileOutputStream(fpath);
              FileWriter fstream = new FileWriter(filepath,true);
              BufferedWriter out = new BufferedWriter(fstream);
              out.newLine();
              out.write(testtext);
              //Close the output stream
              out.close();
           
        }
}

Hope this helps

Visual Studio Team Edition – Some FAQ’s

Q: How many users can I simulate using Visual Studio Team Edition for Software Testers when conducting a Load Test?

A: You may simulate as many virtual users as your hardware allows. Licensing is based per processor and not per virtual user.

Q: What is a Manual Test?

A: A manual test is a test for which there is no automation. Instead, test steps are outlined in a document for the tester to complete. The tester can then report test results and submit bugs as appropriate.

Q: Does Visual Studio Team System support automation testing (e.g., Compuware)?

A: No. However, Visual Studio Team System provides extensibility points out-of-the-box enabling third-parties to develop tools that target Visual Studio Team System.

Q: What is the Test Explorer?

A: Test Explorer is a convenient way to view all of the tests, including manual, unit, and load tests, for a given project.

Q: What is a Test Project?

A: Test projects are standard Visual Studio projects that are specifically created to contain tests. Test projects enable users to draw a clear line between shipping development code vs. code used for quality assurance. Additionally, test projects enable a general manner of organizing tests from a test development standpoint.

Q: Does the test framework manage deploying tests to machines?

A: Yes. Visual Studio 2005 Team System will include a general framework for test deployment that works in both of our supported scenarios: local and remote execution.

Q: Can I use my own tests in the framework and get individual results?

A: Yes. You can do this in two ways:

1) You can wrap an existing test as a Visual Studio Generic Test and get results for it, or

2) You can make your own test type and integrate this into Visual Studio.

Q: How do I migrate my scripts from existing testing tools from third party or Application Center Test?

A: The easiest way to migrate scripts is to re-record them using the browser recorder.

Q: What protocols do you support?

A: We support recording HTTP and HTTPS only; however, other protocols can be tested using Coded WebTests.

Q: How does Visual Studio Team Edition for Software Testers compare/differ from Application Center Test in Visual Studio 2003?

A: The load test features in Team Edition for Software Testers are a completely new product. The features provided far exceed those features provided by ACT.

Q; Can I use these tools to load test Apache/Java based Web applications?

A: Yes, but the tools provided are productivity features designed to ease testing of ASP.NET applications.

Q: Can I test Web services?

A: Yes, although there is no automatic recorder, Web services can be tested by building the SOAP payloads in the test editor.

Q: What is a Web test?

A: A Web test is a test that is used to verify functionality of a Web application. A Web test can be created by recording browser activity and contains a list of Web requests and various properties for each request such as "think time."

Q: What is a load test?

A: A load test is a test that is designed to put a server application under heavy user load to pinpoint performance and/or scalability problems. In Visual Studio, a load test can be based on a Unit Test or a Web Test.

Q: Can I use multiple load clients to generate load?

A: Yes. You can use multiple clients running simultaneously to create very heavy loads.

Q: Can I test ASP and ASP.NET applications?

A: Yes, You can easily test ASP and ASP.NET applications using Visual Studio 2005. There are features for the automatic handling of __VIEWSTATE that make ASP.NET testing easier.

Q: Can I create data driven tests?

A: Yes. Visual Studio 2005 Team System supports the ability to bind input fields and parameters to database files such as Access, SQL Server, or text files.

Q: What protocols are supported?

A: HTTP and HTTPS are supported through the recorder, editors, and test execution engine. Other protocols such as database and other RPC protocols are not directly supported; however, these protocols can be enabled through the extensibility APIs.

Q: Is SSL supported? What about NTLM and Passport?

A: Yes, all of these are supported.

Q: Can I convert my old ACT scripts?

A. There is no conversion utility for ACT scripts or scripts from third party test tool vendors.

Q: Knowing what to monitor during test execution is hard, can you help me?

A; Yes, we provide pre-defined sets of performance counters for common applications such as IIS, ASP.NET, SQL Server and .NET. These pre-defined counter sets can be easily added to a load test.

Q: What information do I receive while executing my tests?

A: During test execution, you receive real-time results that include system resource utilization, request statistics such as response time and content-length, error and overall summary statistics.

Goals of a test framework

A test framework, in addition to consolidating test efforts across the team should try and meet some of the below goals. Offcourse if you are looking at an ideal framework, servicing all would be the best thing
  • Overall Reduction of Test Cost
  • Code Reusability
  • Efficiency
  • Low Cost of Maintaining Existing Test Efforts
  • Reduction of Gaps in Test Coverage Through Intelligent Tests
  • Leveraging of Widely Accepted Tools
  • Low Cost Performance Test Development
  • Data Driven Testing for Reusability
  • Reusable Validation
  • Reduction of Ramp-Up Time
  • Less Overall Maintenance

www.CodeNirvana.in

Powered by Blogger.

Translate

Total Pageviews

Copyright © T R I A G E D T E S T E R