Wednesday, April 10, 2013

Dynamically adding new HTML elements using jquery

There are times, where we need to add a new html elements in client-side using javascript or jquery. Adding a new html element using javascript requires more steps to do. If there is any ready available javascripts functions, then it will be very easy to use.

Here is the javascript function for append new element to the specified target location.

function addElement(tagType, target, parameters) {
        //Create element
        if (typeof tagType != 'undefined')
           var newElement = document.createElement(tagType);

        //Add parameters
        if (typeof newElement != 'undefined') {
            if (typeof parameters != 'undefined') {
                for (parameterName in parameters) {
                    newElement.setAttribute(parameterName, parameters[parameterName]);
                }
            }
        }
        //Append element to target
        if (typeof target != 'undefined') {
            if (document.getElementById(target) != null)
                document.getElementById(target).appendChild(newElement);
        }

        return newElement;
  }

Here is the sample to use the above function

 addElement('input', "maincontent", {
            'id': 'newElementId',
            'name': 'newElementName',
            'type': 'text',
            'value': 'javascript',
            'size': '15'
        });

The above javascript sample can be changed as jquery plugin.

Here is the jquery plugin for append new element to the target.

 $.fn.appendNewElement = function addElement(tagType, parameters) {
            //Create element
            if (typeof tagType != 'undefined')
                var newElement = document.createElement(tagType);

            //Add parameters
            if (typeof newElement != 'undefined') {
                if (typeof parameters != 'undefined') {
                    for (parameterName in parameters) {
                        newElement.setAttribute(parameterName, parameters[parameterName]);
                    }
                }
            }

            //Append element to target
            $(this).append(newElement);

            return newElement;
        }

Here is the sample to use the above jquery plugin

$('#maincontent').appendNewElement('input', {
            'id': 'newElementId',
            'name': 'newElementId',
            'type': 'text',
            'value': 'jquery',
            'size': '15'
        });

 Here is the sample, which uses the above plugins


Friday, March 26, 2010

BarCode Sample in Flex

My friend is working in a flex project.I just helped him in a barcode generation. We just used barcode.swc which is available in adobe.To download barcode.swc click here. Then we explored the sample which is given in that link. Sample which is given in the link is just a swf file but it is not given how to add this swc into our project.So i study the package and class inside the swc. Here is a sample for creating a barcode in flex.
Steps
1. Create a new flex project
2. Add the downloaded "barcode.swc" into the project ( either copy swc into lib folder of your project or manually refer the location of swc in project buildpath)
3. here is the code.

In this sample, I used "Code128B" for barcode generation. There are 5 types of barcodes. Code128B, Code128C, Code39, Code93, CodeI2of5.
The necessary attributes to barcode.

barCodeText="text"
barCodeHeight="50"
addLabel="true"
charGap="5"
xDim="4"

Monday, March 1, 2010

simple mannasim program with nam generation

I am working on ns2. I used cygwin which contains gcc-3.2. I make use of http://paulson.in site to download ns2.29 with mannasim patch. I tried the sample WSN tcl program on mannasim, which seems some complex. So i tried modifying it. I tried nam generation for mannasim program. I tried modifing mannasim-rede-nierarquica. Here is the code mannasim-rede-hierarquica-with-nam

Monday, September 15, 2008

How to use selenium in eclipse

Developing the selenium java along with eclipse makes the work simpler. configuring of selenium in eclipse is much more simpler than other work. I have given you few things regarding selenium eclipse.Test cases can be written in java and it can be executed using eclipse plug-in. Download Selenium Eclipse (Add the downloaded selenium plug in to your eclipse\plugins folder)

To set selenium in eclipse
Eclipse requires JUnit with Ant. The selenium project can also be developed using JUnit with Maven.
Download
Setting up of selenium in eclipse
  • Set system variables
    • JUNIT_HOME=“/*--path of junit jar file c:\selenium\junit-4.4\junit-4.4.jar--*/
  • Set path of system variable for Ant
    • Path=“/*--path of Apache Ant bin c:\Selenium\apache-ant-1.7.1\bin --*/
Procedures for developing selenium project in eclipse
  • Create new Selenium project in Eclipse
  • Then create a new junit testcase in that project. 
  • Add the exported testcase of selenium-ide to the new test case. 
  • Then create a new junit testsuite to run all the testcases. 
  • To run the selenium testcases, start the selenium server (selenium RC) in command prompt. 
  • Then run the test case in junit, which will automatically launch a browser and run the junit scripts in it.

Selenium Remote Control is suitable for site testing

In Previous post I mentioned overview of selenium.In this post i mentioned about why selenium RC is used. And also given you the setting up selenium RC.
  •   Selenium Core needs to make it available from the same web server as the application under test.
  •   The same origin policy states that JavaScript is only allowed to read/modify HTML from the same origin as its source.
  •   If a js file is designed to test google.com, the same origin policy denies to run that js file with google.com; instead, selenium RC can be used to test the site.
  •   Selenium RC makes a proxy server, which allows running the test against the site.
  •   For e.g.: http://www.google.com/selenium-server/MyTestSuite.html.
To Download Selenium RC (Note: FireFox 3 download can be used latest nightly .)
Setting up of selenium RC. Selenium server requires JRE 1.5 (+).
  • Set system variable
    • JAVA_HOME= “/*---path location of Java home for e.g.: c:\jdk1.5.0_12---*/
  • Set class path of client driver for Java
    • Class path= “/*-- C:\Selenium\ selenium-remote-control-1.0-SNAPSHOT\selenium-java-client-driver-1.0-SNAPSHOT\selenium-java-client-driver.jar --*/
Check List
  • Try in command line. Java –version (it will display the version of the java installed on the computer.)
  • Then Try using Selenium Server in Interactive mode. java -jar selenium-server.jar –interactive (This will start the selenium server and allows to create a session, opens the browser and test the site in command prompt)
Note:
If you are going to use firefox 3, then make sure that your download support. Before going to test your automation close all the firefox process in your system,which may also restrict to start browser.

Monday, September 8, 2008

Introduction to selenium

I am right now working on selenium automated testing. Here i have given overview of selenium.
  • Selenium is a testing tool to automate web applications across many platforms.
  • It is open source software.
  • This tool is developed in Java Script and hence supports all the major browsers on all the platforms.
  • Selenium is a cross-browser, cross-platform solution supporting Internet Explorer on Windows and Mozilla-based browsers on Windows, Mac OSX and Linux and Unix.
  • There are 3 variants in selenium, which can be used to create automation suite for web application.
  • Selenium Grid is an extension of selenium RC to test in different environment.

Selenium IDE                Selenium IDE is an integrated development environment for Selenium tests. It is an easiest way to test the create selenium test. It also serves as a starting point for the automation. Selenium IDE comes as Firefox extension, which allows recording, editing and debugging tests.
Features of Selenium IDE
  1. Record and playback.
  2. Auto complete for all common Selenium commands.
  3. Support for Selenium user-extensions.js file and many more.

Selenium Core
                Selenium Core tests run directly in a browser, just as real users do.
Selenium Core used for
  • Browser compatibility testing- Application can be tested in different browsers and operating system.
  • System functional testing- Create tests to verify the application functionality and user acceptance.

Selenium Core tests run directly into application webserver. This allows the tests to run in any supported browser on the client-side. Thus, there should be a write access to the machine web application server is running on to install Selenium Core.

Selenium Remote Control

Selenium RC comes in two parts.
  • A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
  • Client libraries for your favorite computer language.

The RC server also bundles Selenium Core, and automatically loads it into the browser.
Overall architecture of selenium