Tuesday, June 21, 2011

Khayyam On God and Torment

Thou hast said that Thou wilt torment me,
But I shall fear not such a warning.
For where Thou art, there can be no torment,
And where Thou art not, how can such a place exist?

Friday, June 10, 2011

Syntax highlighter script Syntax

Syntax Highlighter

Configuring sonar

I thought i would configure Sonar for my project, which is a Maven archetype Portal Project. Following details the process followed.
1) Download Sonar 2.8 ( Earlier i downloaded sonar 2.7 and got lot of errors due to some bugs not yet fixed in 2.7 , so i recommend sonar).
2) Went into the windows 32 x86 dir and ran startSolar.bat
3) Ran

mvn -X -e clean install sonar:sonar -Dmaven.test.failure.ignore=true


I prefer -X -e because it gives a detailed list of what is going on.

Tuesday, June 7, 2011

Client cert authentication with java

Taken from here



private SSLSocketFactory getFactory( File pKeyFile, String pKeyPassword ) throws ... {
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509);
KeyStore keyStore = KeyStore.getInstance("PKCS12");

InputStream keyInput = new FileInputStream(pKeyFile);
keyStore.load(keyInput, pKeyPassword.toCharArray());
keyInput.close();

keyManagerFactory.init(keyStore, pKeyPassword.toCharArray());

SSLContext context = SSLContext.getInstance("TLS");
context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());

return context.getSocketFactory();
}

URL url = new URL("https://someurl");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(getFactory(new File("file.p12"), "secret"));

Sunday, June 5, 2011

Simple code for Unit Test using WebDriver / Selenium 2

Following is a simple java test to do some testing using Selenium 2 in java.


package com.cisco.swtg.testing;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class Selenium2Example {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.bin","%HOMEPATH%\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
System.setProperty("webdriver.firefox.bin","C:\\FirefoxPortableLegacy35\\FirefoxPortable.exe");
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver chromedriver=null;
WebDriver driver = new ChromeDriver();//new InternetExplorerDriver();// new HtmlUnitDriver();// FirefoxDriver();ChromeDriver
if (driver instanceof ChromeDriver){
chromedriver = (ChromeDriver)driver;

//chromedriver.findElement(By.id("Enter id here"));
}else {
if (driver instanceof FirefoxDriver)
chromedriver= (FirefoxDriver)driver;
else {
if (driver instanceof HtmlUnitDriver)
chromedriver= (HtmlUnitDriver)driver;
}
}
// And now use this to visit Google
chromedriver.get("http://www.cisco.com/cisco/psn/sasi");

// Find the text input element by its name
WebElement element = chromedriver.findElement(By.id("userInput"));
// FirefoxWebElement ele=(FirefoxWebElement) driver.findElement(By.name("USER"));;


// Enter something to search for
element.sendKeys("your - username");

WebElement element2 = chromedriver.findElement(By.name("PASSWORD"));
element2.sendKeys("your-password");

WebElement element3 = chromedriver.findElement(By.name("login-button"));
element3.submit();

try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// Now submit the form. WebDriver will find the form for us from the element
// element.submit();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



chromedriver.findElement(By.id("searchTextBox")).sendKeys("gagandsi");
chromedriver.findElement(By.id("searchButton")).submit();
WebElement username= chromedriver.findElement(By.className("ft-label"));
chromedriver.findElements(By.className("ft-label"));
username.getText();
if(chromedriver.getPageSource().contains("UserName"))
System.out.println("User logged in Successfully");
// Check the title of the page
System.out.println("Page title is: " + chromedriver.getTitle());

//Close the browser
chromedriver.quit();
}
}


What i am up to

Attended Certified ScrumMaster Training by Pete Deemer. Loved it.
Have to give a session on Automated Functional UI Testing using Selenium, so preparing for the same.Discovered that it is still in it's nascent stage. Evaluating Selenium 2 WebDriver. Also have a Dojo training to attend on 9th and 10th of this month. Also have to work on connecting to a website using client certificate authorization.
Prepare for the SCRUM test.