Selenium Webdriver – Get SessionID from a Web Application

Getting SessionID/Cookies from a Web Application using Selenium

package com.test;

import java.util.concurrent.TimeUnit;
 import org.openqa.selenium.*;
 import org.openqa.selenium.firefox.FirefoxDriver;

public class GetSession {
 public static void main(String args[]) throws InterruptedException {
 WebDriver driver = new FirefoxDriver();
 try {
 String domainString = "http://yourURL";
 String baseUrl = domainString;
 driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
 driver.get(baseUrl + "/Login.aspx/");
 driver.findElement(By.id("username")).clear();
 driver.findElement(By.id("username")).sendKeys("username");
 driver.findElement(By.id("password")).clear();
 driver.findElement(By.id("password")).sendKeys("password");
 driver.findElement(By.cssSelector("input.primary.btn")).click();
 String ASPNET_SessionId = driver.manage().getCookieNamed("ASP.NET_SessionId").toString();
 System.out.println(ASPNET_SessionId);
 }
 finally {
 driver.close();
 }
 }
 }
Advertisements

Soap UI – Make JDBC Requests

To do the JDBC request from Soap UI, first we need to install the JDBC driver for the database we are using.

I am using SQL Server and so I have downloaded the JDBC driver for SQL server from here.

http://www.microsoft.com/en-in/download/details.aspx?id=11774

Extract the *.tar.gz file and copy the sqljdbc4.jar file.
Place this jar file under the “bin\ext\” directory where the SoapUI is installed in your machine.

C:\Program Files (x86)\SmartBear\SoapUI-4.6.4\bin\ext\

Now restart the Soap UI.[CLose and then Open]

Lets test this by creating a JDBC test Request.

1. Right Click on a test case and “Add Step” and clic “JDBC Request”
2. Give the driver name as com.microsoft.sqlserver.jdbc.SQLServerDriver
3. Specify the connection string as

jdbc:sqlserver://<servername>:1433;databaseName=<databasename>;user=<username>;password=<password>;

Click on the Test Connection Button.

You should get a prompt like “Connection Tested Successfully”.

Now you are all set to goto make JDBC requests.

Give a sample SQL query under “SQL Query” text area like SELECT * FROM tablename
Run the Request.

You can able to see the results in the xml format.