Showing posts with label Selenium Tutorials. Show all posts
Showing posts with label Selenium Tutorials. Show all posts

Selenium Grid Appium configuration Example

Selenium Grid Appium configuration Example,Connecting appium server to selenium grid for android Testing,Learn APPIUM for android Testing,while working with Appium for android testing using Selenium Grid  we'll face one issue like how to connect to appium server to selenium grid why because Selenium Grid is creating nodes in different machines to run Selenium Scripts in multiple operating systems.

Selenium Grid Appium configuration Example Steps:

Please follow below simple steps to resolve the problem while working with Selenium Grid+Appium.I have configured appium with selenium grid in my test environment using below simple tests.

1.Open Appium
2.Go to General Settings.
3.Enter Server Ip and port.
4.You'll see option like "Selenium Grid Configuration File",just select the check box.


Selenium Grid Appium configuration Example
Selenium Grid Appium configuration Example
Your Configuration file will looks like below and save it in json xml format

In the node config file you've to mentin the browserName, version and platform details and based on these parameters the grid will re-direct tests to the proper device. You've to configure host details and the selenium grid details. For a full list of all parameters and descriptions below chec below file,Once you starts the Appium server and it'll register with the grid, you will see your device on the grid console page:



{
  "capabilities":
      [
        {

          "browserName": "<e.g._device Name",
          "version":"<version_of_Android/IOS_e.g._6.0>",
          "maxInstances": 1,
          "platform":"<platform_e.g.ANDROID>"
        }

      ],

  "configuration":

  {

    "cleanUpCycle":3000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://<host name appium server or ip-address appium server>:<appium_port>/wd/hub",
    "host": <host_name_appium_server_or_ip address appium server>,
    "port": <appium_port>,
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": <grid_port>,
    "hubHost": "<Grid hostname(or) grid ipaddress>"
  }

}

1.Create Nodes in required Machines
2.Need to Start new Nodes for each device as you've configured in different machines. 3.Register those nodes with Selenium Grid Server.
4.Now Start the Server using java -jar selenium-server-standalone-2.43.0.jar -role hub
5.You can register the nodes with this command  - appium -p -U --nodecofig 

  Simple nodeConfig json File


  {
  "capabilities":

      [

        {

          "browserName": "device Name",
          "version":"6.0",
          "maxInstances": 1,
          "platform":"ANDROID"

        }

      ],

  "configuration":
  {

    "cleanUpCycle":3000,
    "timeout":30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url":"http://127.0.0.1:4723/wd/hub",
    "host": 127.0.0.1,
    "port": 4723,
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4789,
    "hubHost": "10.98.45.789"
  }

}


I think you'got enough information on How to Connect appium server to selenium grid topic,in case you'lie my post,please provide your valuable comment and share with your friends.Than you for reading my blog posts.

Cross Browser Testing using Selenium WebDriver

Cross Browser Testing using Selenium WebDriver to run Test Scripts in different browsers like Google Chrome,Firefox ,Internet Explorer etc at a same time then we have to use TestNG Framework for Automating Cross Browser Testing using Selenium WebDriver.

What is Cross Browser Testing?

Cross Browser Testing means testing the application under test(AUT) with different browsers in order to verify all functionalities are working same in all browsers.



Problems if not done Cross Browser Testing

1.Main defect is Design issue.
2.Some functionalities not supports javascript because of browser
3.Some functionalities will not work in some browsers because of configurations.
4.Some time facing issues while uploading/Downloading file formats.
5.Faacing the problems with additional plugins like displaying grid details in applications.
6.Some functionalities will not work changing the campatability mode in browsers.

In order to over come above some problems we have to perform Cross Browser Testing for applications under test(AUT).

Pre-Requisites

1.testng.xml
2.Different browsers drivers(IE Driver,Chrome Driver etc).
3.Test Script class for test cases.
4.Declaring the browsers in a class.
5.@Parameters annotation which Describes how to pass parameters to a @Test method,where we are writing our Test Cases  i.e Test Scripts.

Example for Cross Browser Testing

Prepare textng.xml file to set up parameters for different browsers,follow same code as below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cross Browser Testing" preserve-order="true" verbose="2" parallel="tests">  
<parameter name="Weburl" value="http://www.google.com"></parameter>  
<test name="Internet Explorer">
<parameter name="WebBrowser" value="ie"></parameter>
<classes>
<class name="com.wiki.wiki.Cross"/>
</classes>
</test>
<test name="Google Chrome">
<parameter name="WebBrowser" value="chrome"></parameter>
<classes>
<class name="com.wiki.wikishown.Cross"/>
</classes>
</test>
<test name="Firefox">
<parameter name="WebBrowser" value="firefox"></parameter>
<classes>
<class name="com.wiki.wikishown.Cross"/>
</classes>
</test> 
</suite> 

Now create two classes one class is for driver initialization and Browser setting and second clas is for Test Scripts under @Test anotaitions,follow below classes
Create SelDriver.java class to initialize the driver and browsers set up as below

package com.wiki.seln;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

public class SelDriver {
public static WebDriver driver;
static String baseUrl;

@BeforeTest
@Parameters("WebBrowser")
public void setup(String WebBrowser){

//Adding verfication point using IF Condition
if(WebBrowser.equalsIgnoreCase("firefox")){
driver = new FirefoxDriver();

}else if(WebBrowser.equalsIgnoreCase("ie")){

//For ie browser we have to use System.SetProperty
System.setProperty("webdriver.ie.driver", "F:\\Java_Applications\\Zip Files\\IEDriverServer.exe");
driver = new InternetExplorerDriver();

}else if(WebBrowser.equalsIgnoreCase("chrome")){
//For Google chrome browser we have to use System.setProperty and Chrome Driver
System.setProperty("webdriver.chrome.driver", "F:\\Java_Applications\\Zip Files\\chromedriver.exe");
driver = new ChromeDriver();

}
//Maximize the windows of all browsers
driver.manage().window().maximize();

}
@AfterTest
public void tearDown(){
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}

}

Now i am using Wikishown class and using inheritance wit the help of extends keyword as below

package com.wiki.seln;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Cross extends SelDriver {

@Test(priority=1)
@Parameters("Weburl")
public void testMethod(String Weburl){

//Navigate to URL and Weburl is taking from testng.xml file
driver.navigate().to(Weburl);
//wait until page loads
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.liknText("Manual Testing")).click();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElement(By.linkText("Selenium")).click();

}

}

Above in two classes i have used @Parameters annotation to call parameter name from xml file.Now run xml file as run as -- TestNG Suite then it will run all @Test methods in a class and displays test execution results in Console as well as Test NG icon.

Appium Introduction

Appium is an open source free Automation Mobile App Tool.Automate Native apps, Hybrid  apps and Mobile Web browser Automation.Drives Android , IOS and Windows based Apps.With the help of WebDriver Protocol. Appium is a Cross Platform ,you can write the test scripts against Multiple Platforms with the same API,IOS + ANDROID + WINDOWS.

Appium Introduction:



Before jump into Appium Introduction,we should learn some concepts about Mobile Apps types in the market.Three types of Mobile Apps are their in market,those are

Native Apps : Developed using IOS , Android & Windows SDK Platforms.
Examples : Facebook , What’s Up , Times of India etc.

Hybrid Apps : Hybrid apps are part of Native Apps and Web Apps , it is a wrapper of web View.Hybrid apps build wrapper for already developed Web Sites.
Example : Blogger

Web Apps : Works in Web Browsers and implemented by HTML 5 .

Appium Supported Frameworks:

iOS Platform : Apple’s UIAutomation
Android 4.2+ Platform : Google’s UiAutomator
Android 2.3+ Platform : Google’s Instrumentation - Selendroid 
Windows: Microsoft’s WinAppDriver.

Appium System Requirements:

JDK should be installed
Set JAVA_HOME
Install Android SDK
Node JS
PDA .net for phone connectivity(in phone and Computer)
Emulators

Appium Limitations:

Less than Android version 17 will not work
In IOS script will execution time is more.
Limit Supports for Gestures
Not supports for Toast Messages.

Supported Languages:

Java
JavaScript
PHP
Python
Ruby

Please provide your valuable comments on this post.Thank you for reading My blog posts.

How to Add Screenshots to TestNG Report

How to add screenshot to TestNG Report example post provides complete real time experience coding and Testing is an activity to verify expected results.While Testing application using Selenium Testing it is very important to capture screenshot of application in order to verify any error is occurred in application while selenium script execution.

Manual testers takes screenshot using print screen (PrtSc) keyboard button or using any third party tools in order to log a defect in a Test Management tools for full proof.However coming to Selenium Automation Testing or Automatino Testing taking screenshot and using already taken screenshot in test reports is different.

How to Add Screenshots to TestNG Report

In this post you'll learn exactly how to take the screenshot and save the screenshot with different name or with timestamp and add those screenshots to TestNG Report OR Results in HTML reports.

Trending Posts

Write Test Cases PASS/FAIL in Excel using Selenium
Complete XPATH Tutorial examples
Selenium Data Driven Framework
Selenium HTML Reports Generation
Read Data From Properties files


Please follow below steps to perform the task.

1.Create the method for screenshot
2.Call the method in another classes to use in @Test methods
3.Store the Screenshot in a seperate folder with different name or timestamp.


Class 1:

package com.sel.Selenium.Practise;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Reporter;
import org.testng.annotations.BeforeTest;


public class SelDriver {

public static WebDriver driver;
String baseurl;
public static Properties property;

@BeforeTest
public void openBrowser() throws IOException{

//Reporter .log is a Logger given by TestNG framework.
Reporter.log("Screenshot Capture in TestNG Results Started"); 
System.setProperty("webdriver.chrome.driver", "F:\\Java_Applications\\Zip Files\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
Reporter.log("Chrome Browser is Maximized");
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);

}

public void screenCapture() throws IOException{

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File screenshotName = new File ("E:\\Screenshots\\"+System.currentTimeMillis()+"_"+".png");
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br><img src='"+screenshotName+"' height='300' width='300'/><br>");

}

}


Class 2:

package com.sel.Selenium.Practise;
import java.io.IOException;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class GoogleSite extends SelDriver {

@Test//Test Case one
public void seleniumElements() throws InterruptedException, IOException{

driver.get("https://learn-selenium-automation-testing.blogspot.in");

System.out.println("Open Google site");
Reporter.log("Selenium Site is Open");

screenCapture();//Calling same method created in first class
Reporter.log("Screenshot Capture is done");  
String Title=driver.getTitle();
Assert.assertEquals(Title, "Learn Selenium Automation Testing");
Reporter.log("Verifying the Page with Page Title");
Reporter.log("Screenshot Capture in TestNG Results ended.");
}

}


Now run the second class as TestNG Test ,you'll observe screenshot will added in specific folder with time-stamp ,refresh the project and open index.html file to check screenshot is added ot not in TestNG Results under Reporter Output link of TestNG Report.

Please try above code and let me know in case you're facing any issues.In case code is working fine,Please provide your feedback on below comment box.Thank you for reading and Have a Greate Selenium WebDriver Scripting.

Trending Posts

Write Test Cases PASS/FAIL in Excel using Selenium 
Complete XPATH Tutorial examples
Selenium Data Driven Framework
Selenium HTML Reports Generation
Read Data From Properties files

How to handle UnhandledAlertException in selenium

How to handle UnhandledAlertException in selenium webdriver explains issues facing with new geckodriver versions to open Firefox Browser and issues with Alerts.In this  UnhandledAlertException in selenium lesson,you'll get clear idea to resolve the issues in selenium test scripts.

Trending Posts:



Resolution:

Please watch below video for clear explanation with example.




You'can use below code to handle Alert Exception instead of AutoIT script.

Alert alert = switch().to.alert();
alert.sendKeys(username+Keys.TAB.toString()+Password);
alert.accept();

The above script can be useful to handle proxy Authentication in Firefox Browser and
it'll not work in Google Chrome.

Java Lang NullPointerException in Selenium

Java Lang NullPointerException in Selenium,While running the selenium test scripts you'll face some challenges with the test scripts,in that challenges this is the main important exception,not able to understand why it is displaying and most of the time you'll think that it is raised because of element is not identifying by the Selenium,that is not the proper answer.

Java Lang NullPointerException in Selenium

Java Lang NullPointerException in Selenium


Also Read:


Write TestCase is PASS/FAIL In seleniumTestNG Classpath errorSession ID is null using webdriver after calling quitHow to send extent reports in email with screenshots





Java Lang NullPointerException in Selenium

When coming to Java Lang NullPointerException in Selenium,when passing single webdriver instance to multiple classes,you'll face this type of problems.Please read below instructions  to resolve the same issue in Selenium.

SelDriver Class:



package com.sel.Selenium.Practise;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;

public class SelDriver {  
 public WebDriver driver;
 String baseurl = "http://www.google.co.in";  
 
 @BeforeSuite
 public void openBrowser(){
  
  driver = new FirefoxDriver();
  //driver = new HtmlUnitDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
  
 } 
}

GoogleSite Class:



package com.sel.Selenium.Practise;
import org.testng.Assert;
import org.testng.annotations.Test; 
public class GoogleSite extends SelDriver {
 
 @Test
 public void seleniumElements() throws InterruptedException{
  
  driver.get(baseurl);
  System.out.println("Open Google site");
  
  String Title=driver.getTitle();
  Assert.assertEquals(Title, "Google");
  
  try {
        Assert.assertEquals(driver.getTitle(), "Google's");
      } catch (Error e) {
        System.out.println(e.getCause());
      }   
 } 
}

I', extending the class from SelDriver main class to use WebDriver instance,But when running the above class,you'll face same issue i.e Java.Lang.NullPointerException for some methods.In order to resolve this issue,you need to add static for WebDriver declaration as below.



package com.sel.Selenium.Practise;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;

public class SelDriver {
 
 public static WebDriver driver;
 String baseurl = "http://www.google.co.in";  
 
 @BeforeSuite
 public void openBrowser(){
  
  driver = new FirefoxDriver();
  //driver = new HtmlUnitDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
  
 } 
}


Before Static Method Test Results:




After Changes - Test Results

[TestNG] Running:
  E:\QTPTutorials\Selenium_Workspace\Selenium_Tutorials\testng.xml

Open Google site
null
driver=FirefoxDriver: firefox on WINDOWS (f2f86423-9806-4b4a-ae92-7504e3db59be)
Enter Search Keyword
Clear Enter Keyword
clear works

===============================================
GoogleTestSuite
Total tests run: 2, Failures: 0, Skips: 0
===============================================

TestNG Test Results


Please provide your valuable comments on this solution in case it is resolved your java.lang.nullpointer exception in Selenium.

How To write Test Case is PASS or FAIL using Selenium

How To write Test Case is PASS or FAIL using Selenium,you can write Test case results PASS or FAIL in Excel using J Excel API and TesNG framework with Selenium WebDriver. Most of the time we are working with Excel,Test Cases in order to verify how many test cases are pass/fail in Excel and it is useful for sending the reports to respective managers.


How To write Test Case is PASS or FAIL using Selenium


Write Test Cases PASS or FAIL in SELENIUM

In this post you will learn clear idea about How To write Test Case is PASS or FAIL using Selenium with real time examples.I have created two classes one for ExcelUtility and another for Write the Excel file for each test cases.



Popular Posts

Selenium Xpath Tutorials
Read Data from Properties File
Selenium WebDriver Methods
TestNG Classpath error
Session ID is null using webdriver after calling quit
How to send extent reports in email with screenshots

Pre-Requisites

Step 1: Using JXL jar-You Can Download from Here
Step 2: Selenium WebDriver Configurations
Step 3: xls Test-Data file.
Step 4: addCell()
Step 5: Test Case Results
Step 6: Test Cases
Step 7: Read the xls file FileInputStream
Step 8: Read Workbook from FileINputStream
Step 9: Read Sheets from Workbook
Step 10: Column,rows

ExcelUtility Class

package com.selenium.Utility;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

public class Excelutility {

public String Testcase; 
public WritableSheet writablesh; 
public WritableWorkbook workbookcopy;

@BeforeTest
public void queryParameterization() throws BiffException,IOException,RowsExceededException,WriteException, InterruptedException{

FileInputStream testfile = new FileInputStream("E:\\AppiumTutorials\\Selenium_Practice\\Testdata\\TestData.xls");//Now get 
WorkbookWorkbook wbook = Workbook.getWorkbook(testfile);
//Now get Workbook 
SheetSheet sheets = wbook.getSheet("Query_data");
int Norows = sheets.getRows();
//Read rows and columns and save it in String Two dimensional array
String inputdata[][] = new String[sheets.getRows()][sheets.getColumns()];
System.out.println("Number of rows present in TestData xls file is -"+Norows);
//For writing the data into excel we will use 
FileoutputStream classFileOutputStream testoutput = new FileOutputStream("E:\\AppiumTutorials\\Selenium_Practice\\SeleniumYoutube\\Testdata\\TestData_results.xls");
System.out.println("creating file one");
//To Create writable workbook
workbookcopy = Workbook.createWorkbook(testoutput);
System.out.println("creating file 2");
//To Create Writable sheet in Writable workbook
writablesh = workbookcopy.createSheet("Query_data",0);
System.out.println("creating file 3");

//Using for loop to write all the data to new sheet 
for(int i=0;i<sheets.getRows();i++) { 
for(int k=0;k<sheets.getColumns();k++) {
 inputdata[i][k] = sheets.getCell(k, i).getContents(); 
Label l = new Label(k, i, inputdata[i][k]); 
Label l2 = new Label(4,0,"Results"); 
writablesh.addCell(l); 
writablesh.addCell(l2); 

            }

        }

}


@AfterTest
public void writeexcels(){ 
try { 
workbookcopy.write(); 
} catch (IOException e) { 
e.printStackTrace(); 
} 

try { 
workbookcopy.close(); 
} catch (WriteException e) { 
e.printStackTrace(); 
} catch (IOException e) { 
e.printStackTrace(); 
     } 

  }

}

WriteExcel Class

package com.selenium.elements;
import java.util.concurrent.TimeUnit;
import jxl.write.Label;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.selenium.Utility.Excelutility;


public class WriteexcelFile extends Excelutility {

 WebDriver driver;
 String baseUrl = "https:hploadrunnertutorial.blogspot.in/";

 @Test(priority=1,description="Test Case 1-Open Firfox Browser and open baseUrl")

 public void openBrowser() throws RowsExceededException, WriteException{
 driver = new FirefoxDriver();
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
 driver.get(baseUrl);
 System.out.println("baseUrl is open in Firefox Browser");
 String Title=driver.getTitle();
 System.out.println(Title);

 if(Title.equalsIgnoreCase("HP Loadrunner Tutorial")){

 Testcase="PASS";

 }else{

 Testcase = "FAIL";

 }

 Label l3=new Label(4,1,Testcase);
 writablesh.addCell(l3);
 }

 @Test(priority=2,description="Test Case 2-Submit Query in the System")
 public void submitQuery() throws InterruptedException, RowsExceededException, WriteException{
 String name = writablesh.getCell(1,3).getContents();
 System.out.println(name);
 driver.findElement(By.id("ContactForm1_contact-form-name")).sendKeys(name);
 System.out.println("System enters name field.");
 Thread.sleep(3000);
 driver.findElement(By.id("ContactForm1_contact-form-email")).clear();
 String emails = writablesh.getCell(2,3).getContents();
 driver.findElement(By.id("ContactForm1_contact-form-email")).sendKeys(emails);
 System.out.println("System clears the fields");
 driver.findElement(By.id("ContactForm1_contact-form-email-message")).clear();
 String message = writablesh.getCell(3,3).getContents();
 driver.findElement(By.id("ContactForm1_contact-form-email-message")).sendKeys(message);
 driver.findElement(By.id("ContactForm1_contact-form-submit")).click();
 Thread.sleep(3000);
 String nametext = driver.findElement(By.id("ContactForm1_contact-form-name")).getAttribute("value");
 System.out.println("Print nametext is -"+nametext);
 Thread.sleep(3000);

 if(nametext.isEmpty()){
 Testcase = "PASS";

 }else{

 Testcase = "FAIL";

 }

 Label l3=new Label(4,2,Testcase);
 writablesh.addCell(l3);

       }
}



Please watch VIDEO Tutorial:






Test Results:

How To write Test Case is PASS or FAIL using Selenium


TESTNG Results:



How To write Test Case is PASS or FAIL using Selenium



Please provide your valuable comments on this topic and Please try to practice this example and provide your feedback.For more real time examples,please Read Selenium Complete Tutorials.