Tuesday, 22 April 2014

Step by Step Tutorial for Running your tests on Real Andriod Devices using Selendriod.



Selendroid is a test automation framework for Android native and hybrid applications (apps) and the mobile web. Tests are written using the Selenium 2 client API - that's it!
Before we start let’s have a look at prerequisite. Here is a list of software that needs to be downloaded.
·         Andriod SDK
·         Java SDK (1.6 or higher)
·         Mobile Application APK
·         Mobile Device with its USB Driver
·         Selendroid jar file

Let us now divide the process for setting up Selendriod on Windows into 4 steps mentioned below.
1.      Andriod SDK and Environmental variables setup
2.      Andriod mobile device setup
3.      Selendroid Configuration setup
4.      Mobile Test Scripting

1.     Andriod SDK and Environmental variables setup

If you do not have Andriod SDK on your machine please download it from the link http://developer.android.com/sdk/index.html?hl=sk . A zip file will be downloaded. Unzip the file on your local machine. You will find a folder named sdk, and in sdk folder you will find various folder along with folders name as  ” tools” and “platform tools”. Make a note of the paths for  these 3 folders namely sdk, tools and platform tools.
            We need to configure the environment variable for Android. To set up environment variable for Android in windows follow the steps below.
·         Go to control panel -> System -> Advance system settings -> Environment variables
·         Click on New button under user variable .
·         On the dialogue box, enter variable name as “ANDRIOD_HOME” and variable value as “the path for sdk folder” and save.
·         Under system variables edit path variable, put a semicolon at the end, paste the path for ” tools” folder under sdk , put a semicolon at the end and  paste the path for        ” platform tools” folder under sdk , put a semicolon at the end and save it.
We are now done with configuring the environment variable for Android.

2.     Mobile Device setup

Enable Developer option in mobile device. To enable follow the below steps.
·         Go to Settings in your mobile device
·         Select Developer options
·         Check “Stay awake” checkbox.
·         Also check “USB debugging” check box and click on OK button.
Once Developer option is enabled in mobile connect the mobile device to the computer. To make sure the device is recognized, go to command prompt. Type the command as “adb devices” and hit enter. The mobile device id will be displayed. If not , then the device is not recognized.
            Also make sure JAVA_HOME is set on the machine, if not we also need to configure the environment variable for Java. To set up environment variable for Java in windows follow the steps below.
·         Go to control panel -> System -> Advance system settings -> Environment variables
·         Click on New button under user variable.
·         On the dialogue box, enter variable name as “JAVA_HOME” and variable value as “the path for java jdk folder” and save.
·         Under system variables edit path variable, put a semicolon at the end (if not), paste the path for java jdk folder and append “\bin” to it and save.

3.     Selendroid Configuration setup

Download the selendriod jar files from the link http://selendroid.io/ . In order to use selendriod, selendriod server needs to be started. Follow the below steps to start the server.
·         Place the apk file to be tested in folder where selendroid jar file is located.
·         Go to Command prompt
·         Navigate to the folder where selendroid jar file is located
·         Type the command as “java –jar (name of the selendriod jar file) –app (name of the apk file)” hit enter.
Selendriod will start on the default port 4444.
The set up part ends here for selendriod. We can start writing test cases using Selenium 2 client API.

4.     Mobile Test Scripting

Open eclipse and configure selenium jars in the project. Add test cases to the project. Here is a sample code.
SelendroidCapabilities caps = new SelendroidCapabilities("io.selendroid.testapp:0.9.0");
WebDriver driver = new SelendroidDriver(caps);
WebElement inputField = driver.findElement(By.id("my_text_field"));
Assert.assertEquals("true", inputField.getAttribute("enabled"));
inputField.sendKeys("Selendroid");
Assert.assertEquals("Selendroid", inputField.getText());
driver.quit();

Inspecting elements is done using Selendriod Inspector, which comes with Selendriod. You can find it When you have started selendroid-standalone and you have started a test session at  http://localhost:4444/inspector

For displaying the html source code of a web view please follow these steps:
·         Select in the UI hierarchy the webview you want to inspect and press the ctrl key (this keeps the selection of the element).
·         select the tab Html Source
Selendroid Inspector has a simple build in test case recorder that tries to identify the element that is clicked (on the screenshot) and saves the locator and click command into the Java tab.
For more visit http://selendroid.io/











Monday, 3 March 2014

Hitting Multiple Keys from Keyboard using Selenium Webdriver

Hitting Multiple Keys from Keyboard using Selenium Webdriver

• Suppose you want to hit <ENTER> key from keyboard. You do it as below:

driver.findElements(By.id("your id here")).sendKeys(Keys.ENTER);


• Suppose you want to hit more tha 1 keys from keyboard for example Selecting some text --> Ctrl+Shift+ArrowRight. You do it as below:


driver.findElement(By.id("id")).sendKeys(Keys.chord(Keys.CONTROL, Keys.SHIFT,Keys.ARROW_RIGHT));

Monday, 20 January 2014

Some Useful methods in Selenium WebDriver



isElementPresent/IsText Present :- used to verify if an element is present on the page.

way 1
        boolean isElementPresent(WebDriver driver, By by){
                 try{
                                driver.findElement(by);
                                return true;
                 }catch(NoSuchElementFoundException e){
                                // capture screenshot 
                                return false;
                   }
                 }

way 2
if(driver.findElements(By. any locator stratergy).size()>0){
   return true;
 }else{
   return false;
}
}
 Find if the expected text is present on the page

driver.PageSource.Contains("TEXT that you expect on the page")

Working with Alerts
1.       Fetch the text message.

public static String getAlertMessage(final WebDriver driver) {
String message = null;
try {
Alert alert = driver.switchTo().alert();
message = alert.getText();
alert.accept();
} catch (Exception e) {
message = null;
}
return message;
}
2.       click on cancel/no option on the alert
public static String cancelAlertBox(final WebDriver driver) {
String message = null;
try {
Alert alert = driver.switchTo().alert();
message = alert.getText();
alert.dismiss();
} catch (Exception e) {
message = null;
}
return message;
}
Reading ToolTip
public static String tooltipText(WebDriver driver, By locator){
String tooltip =     driver.findElement(locator).getAttribute("title");
                return tooltip;
}
Selecting Radio Button 

public static void selectRadioButton(WebDriver driver, By locator, String value){ 
List select = driver.findElements(locator);

for (WebElement element : select){

if (element.getAttribute("value").equalsIgnoreCase(value)){

element.click();

}

}
 Selecting CheckBox 

public static void selectCheckboxes(WebDriver driver, By locator,String value)
{
                List abc = driver.findElements(locator);
                List list = new ArrayListArrays.asList(value.split(",")));
                for (String check : list){
                                for (WebElement chk : abc){
                                                if(chk.getAttribute("value").equalsIgnoreCase(check)){
                                                                chk.click();
                                                }
                                }
                }
}

Selecting Dropdown value
public static void selectDropdown(WebDriver driver, By locator, String value){
           new Select (driver.findElement(locator)).selectByVisibleText(value);
 }
public static void selectDropdown(WebDriver driver, By locator, int  index){
           new Select (driver.findElement(locator)).selectByIndex(index);
 }

Uploading file
public static void uploadFile(WebDriver driver, By locator, String path){
driver.findElement(locator).sendKeys(path);
}
Downloading file

1.       Here we will click on a link and will download the file with a predefined name at some specified location.
public static void downloadFile(String href, String fileName) throws Exception{
   URL url = null;
   URLConnection con = null;
   int i;
   url = new URL(href);
   con = url.openConnection();
// Here we are specifying the location where we really want to save the file.
   File file = new File(".//OutputData//" + fileName);
   BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
   BufferedOutputStream bos = new BufferedOutputStream(
   new FileOutputStream(file));
   while ((i = bis.read()) != -1) {
                   bos.write(i);
   }
   bos.flush();
   bis.close();
}

Saturday, 25 May 2013

Selenium Grid - Setup in System

Selenium Grid Setup from Scratch

To be Continued.. with screenshots



Selenium Grid - Setup in System

Selenium Grid Setup from Scratch

To be Continued.. with screenshots



Technical challenges with selenium

Selenium is an Open Source Automation Testing Tool for Web Based Applications.

Challenges faced till date from the beginners day till now are as follows.


1.Locating Web Elements efficiently across the browsers.
2.There is no object repository concept in Selenium, so maintainability of the objects is highly dependent on the test framework architecture.
3.Bitmap comparison is not supported by Selenium
4.No inbuilt reporting capabilities, you need to depend on third party tools such as TestNG, ExtentReports etc..
5. For putting validations or checkpoints/Assertions , have to depend on any unit testing framework such as TestNG , JUnit etc..
6.You need to learn any one of the native language like (.Net, Java, Perl, Python, PHP, Ruby) to work efficiently with the scripting side of selenium
(goLang on the way)

Wednesday, 3 April 2013

Interview Questions


Few Interview Questions For Selenium WebDriver With JAVA


-What class should be extended to use Serialization?
-What is list and set?
-what is hash table?
-what is iterator?
-Tell me about binary search?
-Tell me about buble sort?
-What is Selenium IDE
-How can we do Iphone and Android app testing in selenium
-What technical issues did you face in selenium 
-What is Selenium RC and WebDriver. What is the difference in them (2)
-How many ways can can start the selenium server (1)
-How will you convert integer to String and String to integer in Java (1)
-What do you mean by Object oriented programming. How is it used in selenium? (1)
-how do you download and install selenium? (1)
-Where do you write selenium code if you implement in java (1)
-What all languages are supported by selenium (1) 
-What is Murex testing? Do we use Selenium to test Murex? (3) 
-How to Integrate Jenkins Hudson integration with selenium for running the scripts in schdule time? (6)
-How to compare Text (not Html strings ) (2)
-How to open csv file (1)
-How to run webdriver scripts with different browsers 
-How to do web service testing using selenium webdriver. 
-How to identify webElement on web Page 
-How to draw an annotation(s) on map using selenium webdriver?
-how to handle list(selecting more than one item) in Rc and Webdriver 
-how to handle filedownload in ie and chrome
-How to handle silver light objects 
-How to handles Popups! 

-Interview Ques: How to extract data from webtable or weblist, store it in a file and sort the file

-Is there Assert.assertNotEquals() in webdriver ?

-Can we schedule the execution of test cases 
-Do you any automation tool for desktop application testing? 
-How to verify if the webElement is present or not on the webpage..??
-what are reflection api and how are they used in selenium ?
-How to schedule selenium suite using RC and WebDriver 
-How to create a new file using Java 
-How do you run your automated tests on Mutliple browsers
-How to handle certification error
-How would you deal with Ajax issues?
-What is most difficult challenge you have faced in automating a web application
-How to execute selenium webdriver tests after completion and deployment of build thru Jenkins?
-Give two examples of functionality that cannot be properly tested with automated testing software?
--List the advantage/disadvantages: Selenium WebDriver Vs QTP
-What is inheritance in Java? How is it applied in Selenium? 
-What are the drawbacks of Webdriver? 
-Give me 5 points about what is the use of Framework (jUnit or TestNg) 
-What is the difference between verify and Assert? 
-How to run the test script in selenium on specific time?
-What to do at very first if you want to start a Selenium automation tool in your project?
-How do we keep expected result in the Seleniumj automation script?
-What is the use of Class HtmlUnitDriver and when we have to use the Class HtmlUnitDriver 
-can we handle windows popup using selenium?
-There are 3 fields like House Number, Mobile Number and email address. How will you validate fields

-What is the difference between client-server application and web application?
-How can you test application in multiple browsers in selenium when making the framework 
-How will you run 1000 test cases and generate reports
-What are user extensions
-What is difference between QTP and selenium
-What is the architecture of selenium WebDriver