Latest Event Updates

Code to run batch file in Webdriver

Posted on Updated on

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(“cmd /c BatchFiles\\TempDelete.bat”);
process.waitFor();

————————————————————————–

Below code can be used to create a batch file to delete temperorary fies.

cd %temp%
for /d %%D in (*) do rd /s /q “%%D”
del /f /q *

Installing ANT for Windows 7

Posted on Updated on

1. Download ANT http://ant.apache.org/

2. Unzip it and rename it to ant

3.Set environmental variables JAVA_HOME to your Java environment, ANT_HOME to the directory you uncompressed, to do it on command prompt type this (Assume Ant is installed in E:\ant\.)

set ANT_HOME=E:\ant
set JAVA_HOME=D:\Program Files\Java\jdk1.6.0_03
set PATH=%PATH%;%ANT_HOME%\bin
In windows 7 you can go to Control Panel\All Control Panel Items\System or right click on Computer and then to “Advance system setting”

-Choose Advanced Tab
-Press  Environtmen Variables Button
-In the System Variables, click New Button
Give the Variable Name:ANT_HOME
Give the Value: E:\ant
Click OK

Then,we’ll add new ANT_HOME path,
And Click again on New Button if you do not have ‘path’ Variable in there, if so select it and edit as Give the Variable Name:pathGive the Value D:\Program Files\Java\jdk1.6.0_03\bin;%ANT_HOME%\binClick OK

4. Check wheter ANT works correctly or not.
In the command prompt, type:ant -version

How to handle login pop up window using Selenium WebDriver?

Posted on Updated on

How to handle login pop up window using Selenium WebDriver? Below is the screenshot.

enter image description here

Below is the solution and it worked like charm for me:

se the approach where you send username and password in URL Request:

http://username:password@mytestingenvironment.com

So just to make it more clear. The username is username password is password and the rest is usual URL of your test web

Sample Java code:

  String URL = "http://" + uname + ":" + pwd + "@" + mytestingenvironment.com;
  driver.get(URL);
Alert alert = driver.switchTo().alert();
alert.accept();

How to ZIP files in Selenium

Posted on Updated on

public static void zipFolder(String filepath){
try
{
File inputFolder=new File(‘Mention file path her”);
File outputFolder=new File(“Reports.zip”);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data  = new byte[1000];
String files[] = inputFolder.list();
for (int j=0; j<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inputFolder.getPath() + “/” + files[j]), 1000);
out.putNextEntry(new ZipEntry(files[j]));
int totalcount;
while((totalcount= in.read(data,0,1000)) != -1)
{
out.write(data, 0, totalcount);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
return “Fail – ” + e.getMessage();
}
}

Jenkins Configuration for a Java-based Project

Posted on Updated on

To demonstrate the Sauce plugin for Jenkins, let’s create a new Jenkins Freestyle project for a Java project.

From the Jenkins dashboard page, click New Job

New Job

Enter ‘Sauce Java Demo’ in the Job Name field and select Build a free-style software project.

New Freestyle Project

Our sample code is located in github, so select Git in the Source Code Management section, enterhttps://github.com/rossrowe/sauce-ci-java-demo as the repository URL and enter master in the branch specifier.

Git Setup

Now let’s add a build step which will run our tests. Click on the Add Build Step menu in the Build section, and selectInvoke top-level Maven targets

Invoke Maven

Enter test in the Goals field.

Maven Goals

Now let’s enable the Sauce OnDemand support for a Jenkins Job can be enabled by checking the Sauce OnDemand Support checkbox.

Sauce Configure

Select the Enable Sauce Connect? check box. When selected, the Sauce plugin will launch an instance of Sauce Connect prior to the running of your Job. This instance will be closed when the Job completes.

Click on the WebDriver radio button and select a browser to run our tests against (let’s pick Firefox 15 running in Windows 2008)

Sauce Configure

Sauce OnDemand supports a wide range of browsers, but some browser combinations are only supported for SeleniumRC or WebDriver tests. The multi-select lists beneath the SeleniumRC and WebDriver radio buttons are populated by retrieving the list of respective supported browsers via the Sauce REST API.

If a single browser is selected, then the SELENIUM_PLATFORMSELENIUM_VERSIONSELENIUM_BROWSER and SELENIUM_DRIVERenvironment variables will be populated to contain the details of the selected browser. If multiple browsers are selected, then theSELENIUM_BROWSER environment variable will be populated with a JSON-formatted string containing the attributes of the selected browsers. An example of the JSON string is:

[
    {
    "platform":"LINUX",
    "os":"Linux",
    "browser":"firefox",
    "url":"sauce-ondemand:?os=Linux&browser=firefox&browser-version=16",
    "browser-version":"16"
    },
    {
    "platform":"VISTA",
    "os":"Windows 2008",
    "browser":"iexploreproxy",
    "url":"sauce-ondemand:?os=Windows 2008&browser=iexploreproxy&browser-version=9",
    "browser-version":"9"
    }
]

If the SeleniumRC radio button is selected, then a Starting URL field will also be displayed.

The plugin will set a series of environment variables based on the information provided on the Job Configuration. These environment variables can either be explicitly referenced by your unit tests, or through the use of the [selenium-client-factory] library.

  • SELENIUM_HOST – The hostname of the Selenium server
  • SELENIUM_PORT – The port of the Selenium server
  • SELENIUM_PLATFORM – The operating system of the selected browser
  • SELENIUM_VERSION – The version number of the selected browser
  • SELENIUM_BROWSER – The browser name of the selected browser.
  • SELENIUM_DRIVER – Contains the operating system, version and browser name of the selected browser, in a format designed for use by the Selenium Client Factory
  • SAUCE_ONDEMAND_BROWSERS – A JSON-formatted string representing the selected browsers
  • SELENIUM_URL – The initial URL to load when the test begins
  • SAUCE_USER_NAME – The user name used to invoke Sauce OnDemand
  • SAUCE_API_KEY – The access key for the user used to invoke Sauce OnDemand
  • SELENIUM_STARTING_URL – The value of the Starting URL field

By default, the plugin will use the authentication details specified in the Jenkins administration section. However, this can be overriden at the Job level by enabling the Override default authentication? checkbox and specifying values in the Username and Access keyfields.

Note: These values are set automatically by the Jenkins plugin. If the Enable Sauce Connect? checkbox is selected, then theSELENIUM_HOST and SELENIUM_PORT variables will default to localhost:4445. If the checkbox is not set, then the SELENIUM_HOST andSELENIUM_PORT variables will be set to ondemand.saucelabs.com:4444.

The values for the SELENIUM_HOST and SELENIUM_PORT environment variables can be overridden by explicitly specifying the host and port in the Sauce OnDemand Host and Sauce OnDemand Port fields, which can be displayed by clicking on theSauce Connect Advanced Options button.

Sauce Configure

Embedding Sauce Reports

The plugin also supports the embedding of Sauce Job reports within the display of test results. This requires the tests executed by the Jenkins job to produce result files in the JUnit XML report format.

To enable this, select the Add post-build Action within the Post-build Actions section.

Add Post-build action

From the pop-up menu, select the Publish JUnit test result report option.

JUnit Post-build action

Enter target/surefire-reports/*.xml as the path to the test reports that are produced by your Jenkins Job, and check theEmbed Sauce OnDemand reports checkbox.

Embed Sauce Reports

That’s it, our configuration is all setup, let’s run the tests!

How to use Subversion with Eclipse

Posted on Updated on

Adding Subclipse to Eclipse

Subclipse is a project to add Subversion support to the Eclipse IDE. We’ll use Eclipse’s update manager to add Subclipse to our Eclipse IDE. From the Help menu in Eclipse, choose Software Updates > Find and Install to open the update manager.

Figure 1. The Eclipse update manager

Eclipse update manager

In addition to using this to look for software updates, we can use the update manager to find and install new features, such as Subclipse. Be sure that Search for new features to install is selected, then click Next to continue. Eclipse displays the next update manager panel.

Figure 2. Update manager sites

Update manager sites

Since we’re after a specific feature, un-check the existing sites, then click New Remote Site to display the New Update Site dialog (see Figure 3). We’ll use this to add the Subclipse update site to the list.

Figure 3. Adding a new update site

Adding a new update site

Enter whatever you want for the Name (Subclipse is a good choice) and enter the following for the URL:http://subclipse.tigris.org/update_1.0.x (the current Subclipse update site). Click OK to add the Subclipse update site to the list in the update manager.

Click Finish in the update manager window to begin searching for new features. In this case, the new feature we’re after is Subclipse. After a few moments, the update manager’s search is complete, and it displays the search results.

Figure 4. New features we can install

New features we can install

Check Subclipse (you can click the disclosure triangle to see what exactly is included in this feature), then click Next to view the feature’s license terms. Accept the terms, then click Next to review the features you’ve chosen to install. Click Finish to download and install Subclipse.

The update manager downloads the Subversion components. Before installing anything, Eclipse will warn you that the features aren’t digitally signed (Figure 5). This is your last chance to cancel the installation. Click Install All to continue the installation.

Figure 5. Subclipse isn’t digitally signed

Subclipse isn't digitally signed

Once Subversion has been installed, Eclipse warns you that you might need to restart the IDE to activate the new features (see Figure 6). Restart Eclipse, just in case.

Figure 6. Restart Eclipse after installing new features

Restart Eclipse after installing new features

When Eclipse comes back up, Subclipse is installed and ready to go.

If you’re running Eclipse on Mac OS X or Linux®, you may need to install the JavaHL library, which is described in the Troubleshooting section of the Subclipse FAQ (see Resources). Do this before you continue trying to use Subclipse.

A quick test

It’s always nice to test a new feature once you’ve finished the installation; we’ll try checking out a copy of Subclipse from their Subversion repository to make sure it’s been properly installed.

From Eclipse’s File menu, choose Import to display the import manager (see Figure 7). Choose Checkout Projects from SVN, then click Next.

Figure 7. The import manager

The import manager

On the Select/Create Location panel (see Figure 8), we need to create a new location (since we don’t have any configured yet), so click Next to continue. If the Next button is disabled, switch to the Use existing repository location option, then back to Create a new repository locationto enable the Next button.

Figure 8. Creating a new repository location

Creating a new repository location

In the next section (see Figure 9), add the repository URL (http://subclipse.tigris.org/svn/subclipse/) to the Url field, then click Next. After a moment, Eclipse prompts you for user ID and password. If you don’t have an account on the Subclipse site, enter guest for the user ID and a space for the password, check the Save Password box, and click OK.

Figure 9. Add the repository URL

Add the repository URL

Eclipse displays the folders in the Subclipse repository (see Figure 10). Expand the trunk and choose the subclipse folder, then click Finish to check out your own copy of the Subclipse project’s source code. Since you have no idea what this is, choose Simple > Project when the New Project wizard prompts you.

Figure 10. Subclipse repository

Subclipse repository

Basic Subversion operations

At this point, we’ve installed Subclipse successfully, which added support for Subversion servers to our Eclipse setup, and we’ve tested Subclipse by downloading the current Subclipse source code from the repository. Now we should look at doing something with our own code and our own Subversion repository.

Before I show you how things work with Subversion, I’ll tell you a little bit about my repository. It’s hosted on a machine called dogma on port 8000, and I’ve created a new developerworks repository for code associated with my developerWorks articles. I’m going to put my projects directly in the root of the repository. Other repositories often have folders named trunk, tags, and branches off the root, for development versions, tags, and branches, but I don’t expect to need to worry about tagging or branching the developerWorks article code.

I’ve added two projects, forkWork and threadWork, from my first developerWorks article. My Eclipse workspace (see Figure 11) also contains three other projects from developerWorks articles (getopt_demo, getopt_long_demo, and readdir_demo).

Figure 11. My Eclipse C/C++ projects

My Eclipse C/C++ projects

Now we’re ready to get to work.

Adding a project to the repository

To add a new project to your Subversion repository, right-click the project (in any of Eclipse’s project views or the Navigator view) and chooseTeam > Share Project from the menu. Eclipse displays the Share Project dialog.

Figure 12. The Share Project dialog

The Share Project dialog

Select SVN from the list of repositories currently supported by your Eclipse, then click Next. The next dialog (see Figure 13) lets you choose an existing repository location, or you can create a new one.

Figure 13. Selecting a repository location

Selecting a repository location

If your repository is already listed (as you can see, I’ve added mine), select it, and click Finish. If your repository isn’t listed, add it (see A quick test for instructions) and continue. Eclipse creates a new directory in the repository with the same name as your project, and displays a list of all files and folders in the project.

Figure 14. Adding a project’s contents

Adding a project's contents

Enter a suitable comment describing this project in the top field, then click Select All to check all of the files from the project. Click OK to check in your project and transmit its current state to the Subversion repository.

Subversion’s commands and output are displayed in the Console view, usually found at the bottom of your Eclipse window, if you want to see exactly what Subclipse did with your project.

Updating a project

One of the key features of a version-control system is the ability for other developers to continue development and commit their changes whenever they’re ready. To download these changes and integrate them with your local copies, you need to update the project.

Right-click on the project you want to update, then choose Team > Update from the menu. Eclipse retrieves any changes from the repository and attempts to merge them with your local copy.

Adding a file or directory

If you add a file to your project (see Figure 15), it’s not automatically part of version control — you need to specifically add it to the repository. In the screenshot, you can see that I’ve added a ReadMe.txt file to the threadWork project.

Figure 15. Adding a new file

Adding a new file

Right-click the new file, then choose Team > Add to Version Control. That’s it! The next time you commit your changes in this project to the repository, the new file will also be checked in.

Deleting a file or directory

If you’ve added a file to the repository that’s no longer relevant to your project, you can easily delete it. Right-click the file, then choose Delete. No need for the Team menu, Subclipse flags the file for deletion automatically and removes it from your project. The next time you commit your changes to the repository, the file is deleted.

Renaming a file or directory

To rename a file or directory under Subclipse’s control, right-click it, then choose Rename. Type the item’s new name in the entry field and clickEnter. The file is renamed in the project, and the rename operation (an Add for the new name, and a Delete for the old one) is queued for your next commit. In Figure 16 you can see the threadWork project after I’ve renamed main.c to threadWork.c, but before I’ve committed my change. Note the little blue plus sign Subclipse has added to the “new” file to indicate that it’s scheduled for addition in the next commit.

Figure 16. Renaming a file is atomic, even though it’s an add and a delete

Renaming a file is atomic, even though it's an add and a delete

Ignoring files

If your project generates files, or otherwise includes files that you don’t want to check in to the Subversion repository, you can tell Subclipse to ignore them. Right-click the file or directory you want to exclude from version control, then choose Team > Add to svn:ignore to display the Add to svn:ignore dialog.

Figure 17. Ignoring resources that don’t belong in version control

Ignoring resources that don't belong in version control

Click OK to add this specific file to the svn:ignore property for the project’s directory. Choose Wildcard extension to ignore all files with the current file’s extension, or choose Custom pattern to add your own wild card to the ignore list. These changes to the ignore list will be added to the repository the next time you commit your changes.

Committing your changes

Once you’re happy with your changes to the project, you’ve made sure your code compiles, and you’ve tested your changes, you should commit them to the Subversion repository. This acts as a backup in case your workstation self-destructs, and it lets other developers update their local copies to include your changes.

Be sure to update your project (see “Updating a project”) before attempting to commit your changes. Right-click the project and choose Team > Commit from the menu. Eclipse displays the Commit dialog (see Figure 18), which summarizes your changes.

Figure 18. Committing your changes to the repository

Committing your changes to the repository

If you look carefully, you’ll see a property change to the project’s directory (I’ve added to the svn:ignore property to keep certain files out of the repository) and that main.c was deleted while threadWork.c was added. That pair of changes actually represents one operation (a file rename).

At this point, you can deselect resources if you want to keep them out of the repository. This might be helpful if you’re partially finished work in one file, and don’t want to check in an incomplete change. Enter a suitable comment in the top text field, then click OK to check in your changes to the repository.

Summary

The Subclipse project integrates support for the Subversion version-control system with Eclipse’s excellent team project management features, which only support CVS servers out of the box. Using Eclipse’s update manager, it’s easy to add Subclipse to your Eclipse installation, which lets you use this superior (in my opinion, at least) version-control system directly from Eclipse.

While adding projects to a repository — and managing your project’s resources once it’s there — can be daunting for folks unfamiliar with Subversion, the procedures for common operations are straightforward. This article walked you through the everyday operations to help familiarize you with Subclipse.

INSTALLING JDK ON WINDOWS

Posted on Updated on

1.Environment Used

  • Java SE 6 Update 29
  • Windows (XP/Vista/7) OS

Downloading Java Development Kit (JDK):

You can download latest version of JDK from this location

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Click on the download link to go to the download page.

Download the JDK suitable for your system requirement (Windows x86 for 32bit windows or Windows x64 for 64bit windows) to a safe location on your machine.

Installing Java Development Kit (JDK):

Step 1:

Double click the downloaded JDK exe file. Click the “Next” button.

Step 2:

The “Custom Setup” window allows you to select which parts of the JDK you want to install. If you want to change the installation directory click on change and specify the location where jdk will be installed. It is recommended to stick with the default settings. Click the “Next” button.

Step 3:

JDK “installing” window appears. It will take a few minutes to install the program features of the JDK.

Step 4:

By installing JDK, JRE will also be installed. Select Java Runtime Environment (JRE) installation location.

Step 5:

When the “Complete” screen appears, click on the “Finish” button. Now you have successfully installed the Java Development Kit!

Configuring the installed JDK on Windows:

The installed JDK must be configured to the windows environment so that the Java compiler (javac) and runtime (java) becomes available for compiling and running the Java application from any location on Windows.

NOTE: If JDK is not configured on windows environment then to compile and run your Java applications you must place them in <JAVA_HOME>/bin/ folder.

For Windows Vista/7:

    1. Click on Start -> Right click Computer -> Select Properties

    1. Click on “Advanced system settings” from left side Tasks menu.

    1. Click on “Advanced” tab and click on “Environment Variables…”.
NOTE: For earlier Windows version:
Right click “My Computer” -> Select “Properties” -> “Advanced” tab and click on “Environment Variables…”
    1. Select Path variable from “System variables” and click on “Edit…” and go to the end of the “Variable Value” and place a semi-colon (;) and add “<Your JDK installation folder>\bin” path as shown below.

  1. Click OK -> OK -> OK. Now you have successfully configured JDK and ready to develop applications in Java.
  2. Now open Command prompt and type “javac -version” and it should show the version number which you installed.

javac is the primary Java compiler, included in the Java Development Kit (JDK).

Also type “java -version” which is Java runtime included in JDK. Sometimes you may want to restart the computer for the PATH settings to take effect.

Done! If you haven’t encountered any problems, then the installation and configuration is complete.

INSTALLING M2ECLIPSE – MAVEN PLUGIN FOR ECLIPSE

Posted on Updated on

In this tutorial, we will see how to install m2eclipse plugin which provides Maven integration in Eclipse IDE. m2eclipse provides first-class Apache Maven support in the Eclipse IDE, making it easier to edit Maven’s pom.xml, run a build from the IDE and much more.

Environment Used

  • Java SE 6
  • Eclipse Juno for Java EE Developers (4.2) IDE
  • Maven Eclipse Plugin – m2eclipse version 1.2

Installing JDK

JDK should be installed with proper environment set up. Read this page for installing the JDK and setting up the environment.

Installing Eclipse IDE

Make sure you have Eclipse IDE installed. If you need to install Eclipse, you can read this page.

Online Installation (From Update Site) of Maven Plugin m2eclipse

http://download.eclipse.org/technology/m2e/releases

You can install Maven plugin for Eclipse via update site, simply copy the above update site link address and paste it into Eclipse’s “Update” or “Install New Software” manager as explained below.

Step 1:

Installing m2eclipse is fairly simple. Start Eclipse then go to:
Help -> Install New Software…

Copy this link http://download.eclipse.org/technology/m2e/releases for the latest Stable Release into Eclipse and hit Enter.

When the site loads, select the features to install, or click the Select All button. For our requirement select “Maven Integration for Eclipse” as shown above.

Checking [x] Contact all update sites during install to find required software might take sometime and this is optional.

Step 2:

  • Click Next to view Installation Details.
  • Click Next to agree the license terms, and click Finish.

Step 3:

If you get any warning message when installing, click OK to continue.

This will take few minutes to install the Maven plugin and once done restart the Eclipse.

Creating New Maven Project in Eclipse

After installing the Maven plugin for Eclipse, you can check if the installation is successful by creating a new Maven project.
You should see a Maven folder in the New project wizard as shown below.

Now you have successfully installed “Maven plugin – m2eclipse” in Eclipse IDE.

Create an object repository for Selenium WebDriver

Posted on Updated on

Problem

It is very useful to extract the locators from the test code. This makes your test code much more maintainable and readable. Beside of that there is no need to recompile the project after changing the identifiers. There are many ways to do it, but we will see just one way in this example. It can be done by the Java properties file. Just load the file in front of running the tests and then you can use all the properties, that is basically everything what you have to do. The properties file is just flat text. That is why there is no need to recompile the whole source code once locators have been changed. We can also make use of the same locators in multiple test cases. These are big advantages of using a object repository.

Prerequisites

We can install Eclipse as preferred IDE to setup a Java test project.

Solution

  1. We have to create a properties file, given this name locators.properties. The part before the equals sign is the key, the part after the equals sign is the value. We can give the following content to the file:
1
2
login.username.textfield=css=input#username
login.password.textfield=css=input#password
  1. We have to load the properties file, before we can call the locators. We have to initiate the properties object and load the contents of the file in it. We can do this with the following code:
1
2
3
4
5
6
Properties props = new Properties();
try {
    InputStream in = getClass().getResourceAsStream("locators.properties");
    props.load(in);
} catch (IOException e) {
}
  1. We can use the object repository, once the key/values are actually loaded in the properties object. We can use the value in our tests, by calling the key parameter, like this:
1
props.getProperty("login.username.textfield")

What has been done

We are loading a key/value pairs into a properties object. Make sure you will do this in front of running any tests. Finally we are able to get the value by it’s key.

Source Code

The source code is available on GitHub at the following location: https://github.com/roydekleijn/HowToUsePropertiesFile

– See more at: http://selenium.polteq.com/en/category/tips-tricks/#sthash.G7LIVZco.dpuf