Posts

Showing posts from November, 2015

FitNesse Program

Sample FitNesse program, package com.SamplePackage; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class FirstClass { WebDriver driver; //Constructor method public FirstClass(String browser, String baseURL) {     if (browser.equalsIgnoreCase("*iexplore"))     {         driver = new InternetExplorerDriver();         driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);     }     else if (browser.equalsIgnoreCase("*firefox"))     {         driver = new FirefoxDriver();     }     else if (browser.equalsIgnoreCase("*chrome"))     {         driver = new ChromeDriver();     } } public boolean open(String URL) { driver.get(URL);   

Browsermob Sample Program

//Import dependency classes from Selenium standlone jar file import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; //Import dependency classes from BrowserMob-Proxy jar file import org.browsermob.proxy.ProxyServer; import org.browsermob.core.har.Har; import org.openqa.selenium.By; import org.openqa.selenium.Proxy; import java.io.FileOutputStream; public class SampleClass {     public static void main(String[] args) throws Exception {         String strFilePath = "< Define Your Local System Path here >";         // start the proxy         ProxyServer server = new ProxyServer(4444);         server.start();         //captures the moouse movements and navigations         server.setCaptureHeaders(true);         server.setCaptureContent(true);         // get the Selenium proxy object         Proxy proxy = server.seleniumProxy();         /

Junit Parallel Run Program

Below is the sample helper class needed to run parallel JUnit test: package default; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.junit.runners.Parameterized; import org.junit.runners.model.RunnerScheduler; public class Parallelized extends Parameterized {       private static class ThreadPoolScheduler implements RunnerScheduler {     private ExecutorService executor;         public ThreadPoolScheduler() {       String threads = System.getProperty("junit.parallel.threads", "16");       int numThreads = Integer.parseInt(threads);       executor = Executors.newFixedThreadPool(numThreads);     }         @Override     public void finished() {       executor.shutdown();       try {         executor.awaitTermination(10, TimeUnit.MINUTES);       } catch (InterruptedException exc) {         throw new RuntimeException(exc);       }

Junit - Single Run Program

package default; import java.net.URL; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class Sample {    private WebDriver driver;    @Before   public void setUp() throws Exception {      DesiredCapabilities capability = DesiredCapabilities.chrome();     driver = new RemoteWebDriver(new URL("<Application URL>"),capability);   }    @Test    public void testSample() throws Exception {      driver.get("http://www.google.com");     WebElement element = driver.findElement(By.name("q"));     element.sendKeys("Selenium Junit");     element.submit();      System.out.println("Page title is: " + driver.getTi

QcIntegration.java

This class file is used to  perform operation in QC by  invoking some inbuilt functions specified in the " OtiClient.Jar " file.  So whoever wants to communicate with QC or ALM, they can use this Class file and otiClient.jar file to make their work simple. QcIntegration.java import com.qc.ClassFactory; import com.qc.IBaseFactory; import com.qc.IList; import com.qc.IProjectDescriptor; import com.qc.IRun; import com.qc.IRunFactory; import com.qc.ITDConnection4; import com.qc.ITSTest; import com.qc.ITestSet; import com.qc.ITestSetFolder; import com.qc.ITestSetTreeManager; import com4j.Com4jObject; public class QcIntegration {          public static void sendRequest(String strTestCaseId, String strStatus) {         ITDConnection4 connection=null;                  //QC url         String url = "http://<QCURL>/qcbin";         //username for login         String username = "<QC USERNAME>";         //password for login

TestCaseOne.java

This is a sample selenium java program created to perform some action in the Google page and update the results into QC. This Class is extended by the  QcIntegration.java program which has function to perform operation in QC by  invoking some inbuilt functions specified in the " OtiClient.Jar " file. TestCaseOne.java import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class TestCaseOne extends QcIntegration{     public static void main(String[] args){         /**         * @param args         */         String baseUrl="http://www.google.co.in";         String strSearchKeyword = "test";         String locSearchTextField = "q";         String locSearchButton = "q";         //Need to pass the Test case name         String strTestCaseID = "<TestCaseName>";         String strTestCaseStatus = "";         WebDriver dr

DLL to Jar file conversion

Steps to get OTIClient.jar file to perform operations within QC 1) Open the HP Quality Center in IE browser and navigate to QC Login page 2) Navigate to the local path of the HP folder to get the OTAClient.dll (Mostly the Path would be “C:\Users\<UserName>\AppData\Local\HP\ALM-Client\172\OTAClient.dll”) 3) In order to work with OTA, we need to register that DLL with the system by using below command in the run prompt regsvr32 "C:\Users\<UserName>\AppData\Local\HP\ALM-Client\172\OTAClient.dll" 4) Convert the DLL file into Jar format to support the script integration with QC.       a. Download ‘ com4j.jar file’, downloaded file will be in zip format, so please extract that zip file in some folder.        b. Navigate to the extracted folder in command prompt        c. Enter the following command java -jar tlbimp.jar -o alm -p com.qc "C:\Users\<UserName>\AppData\Local\HP\ALM-Client\172\OTAClient.dll"