Friday, June 8, 2018

Create Selenium WebDriver using Java Factory Pattern

Hi Friends,

In Factory pattern, we create an object without exposing the code to the client and refer to a newly created object using a common interface.

This is widely used java pattern for creating the object. 

Here is the UML diagram for creating the webDriver object. 




Click here to download the code from GitHub repo

Note: This is just an idea. Future enhancement can be done based on requirement. 


Thursday, June 7, 2018

Create Selenium WebDriver object using Singleton Java pattern

Hi Friends,

You must be knowing about the java patterns and it's advantage. In this post, I am going to create webDriver object using Singleton java pattern.

Singleton means to define a class that has only one instance and provides a global point of access to it.

Singleton class :


public class WebDriverSingleton {

private static WebDriver driver;
private static WebElement element;

private WebDriverSingleton() {
}

public static void initDriverInstance(Browsers browserName) {
 // code for init driver object
}

public static void openURL(String url){
// open url code
}
public static void quit() {
// code for quit driver
}

public static WebElement findElement(Locator locator, String value) {
// code for findElement 
}

// add all the other required method here
}


Test class :

public class Test_1 {
@BeforeClass
public void Setup() {
WebDriverSingleton.initDriverInstance(Browsers.CHROME);
WebDriverSingleton.openURL("http://newtours.demoaut.com");
}
@Test
public void TestCase_1() {
WebDriverSingleton.findElement(Locator.NAME, "userName").sendKeys("testuser");
WebDriverSingleton.findElement(Locator.NAME, "password").sendKeys("testpassword");
WebDriverSingleton.findElement(Locator.NAME, "login").click();
}
@AfterClass
public void killDriver() {
WebDriverSingleton.quit();
}
}

Click Here to Download code from github 

Wednesday, October 23, 2013

Record objects for CUITe using CUITe_ObjectRecorder


  • Download  CUITe_ObjectRecorder from below link
·         CUITe for .NET v4.5 ( try this and install it – start  CUITe_ObjectRecorder.exe )
·         CUITe for .NET v4


Steps to create CUITe Object
  • Address: Add user which user want to test
  • Click on Record button ( recorder started to record object)
  • Click on User Name, Password textbox and Sign-in button
  • Tool will generate code below application
  • Click on Code icon ( Notepad will open with code)
  • Copy the object code which are generated while recording object
  • Paste in object repository file which created for object repository ( in .cs file)
That’s all, your object repository will be looking like below

  • User has to add following code:
  • ORLogin class should be public– so that class can be use globally
  • Inherit the class ORLogin from CUITe_BrowserWindow
  • If user have created folder for object repository folder then namespace would be display folder name as well

CUITe Configuration

This is small demo for configuring Visual studio 2012 for CUITe, follow the steps to make CUITe work with VS 2012.
 
  •   Install following version of Visual studio
·         Visual Studio 2010 Premium or Ultimate and Feature Pack 2 OR Visual Studio 2012 Premium or Ultimate

  •  Download CUITe Framework from below link
·         This link shows list of projects, from these project use CUITe, CUITe.snk and CommonAssemblyInfo.cs

·         Follow these steps to use UITestPluginForSilverlight dll.
1. Add Microsoft.VisualStudio.TestTools.UITest.Extension.Silverlight from %Program Files%\Common Files\Microsoft Shared\VSTT\11.0\UITestExtensionPackages
2. Added using Microsoft.VisualStudio.TestTools.UITesting.SilverlightControls


  •    Download CUITe.dll from below link
·         CUITe for .NET v4.5 ( try this for VS 2012)
·         CUITe for .NET v4
·         Run above set up and copy CUITe.dll to project folder
·         CUITe_ObjectRecorder.exe - Used for Recording Object for CUITe


  • Install test Agent if user want to run script in other system without installing VS 2012.