Posts

Showing posts from March, 2019

XPath Technique for finding parent element using child element's property

Image
Xpath element locator is used for finding unique list element(parent) with the help of its child element may be down any level from parent. Refer to attached Screenshot .We want to find parent row element, which has a child hyperlink with text ‘sed’ down somewhere in parent row.*first create path for child hyperlink element//a[@class=’item-name-link’ and contains(text(),’sed’)]* Now create xpath for parent list element which are multiple in nature.//div[@class=’file-list-item-wrapper’]*Now create unique xpath for parent list element by joining two attributes as mentioned below  //div[@class=’file-list-item-wrapper’ and .//a[@class=’item-name-link’ and contains(text(),’sed’)]] **Note:- “.//” denotes that child element is located somewhere below in the hierarchy of parent element.. *************************************************************************************** QACult Best Software Testing Courses in Chandigarh tricity .- We love to enhance your knowledge. QA

Popup window handling

Image
//Getting the Current window handle in form of string   (Note : Output will be for current window and will be in form of immutable String) String winHandle = driver.getWindowHandle();   System.out.println("Current Page handle is : " + winHandle ); //Getting the handles for all the windows of the current website via java.util.Set  in form of collection (Note : Output will be for all the windows  and will be in form of Set {Collection} ) java.util.Set winHandles = driver.getWindowHandles(); System.out.println(windows.size());  //Output for the number of windows     Sample Working code for Naukri.com where we are closing all extra windows and getting back to main window: public static void main(String[] args) {          WebDriver driver = new ChromeDriver();         driver.get("http://naukri.com");         WebDriverWait wait =new WebDriverWait(driver,30);         String homePage=driver.getWindowHandle();         System.out.println("

Jenkins Build server, its importance, Installing and configuring Jenkins on Windows.

Image
Jenkins is a open source tool which offers a simple way to set up a continuous integration or continuous delivery environment for almost any combination of languages and source code repositories. Jenkins is available as a Java WAR archive and installer packages for the major operating systems.Jenkins doesn’t eliminate the need to create scripts for individual steps but it gives a faster and more robust way to integrate your application. Jenkins have more than 1000 plug-in to make the work easier and to add more attractive features to your build management. Steps to install 1) Download Jenkins war file from https://jenkins.io/ in the directory of your choice. 2) Start Jenkins with command java –jar jenkins.war 3) Configure  with one time installation 4) Provide password 5) Install default plugins 6) Create user and then create your job. *************************************************************************************** QACult Best Software Testi

How to escape black screen of browser

Image
//Escaping black screen of browser using Action class and with keyboard button in selenium Actions act = new Actions(driver); act.sendKeys(Keys.ESCAPE).build().perform(); //Sample working  code for facebook.com login script public static void main(String[] args)throws InterruptedException { WebDriver driver = new ChromeDriver(); // driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); String appurl = "https://facebook.com"; driver.get(appurl); WebElement username3 = driver.findElement(By.cssSelector("input[id='email']")); username3.clear(); username3.sendKeys("qacult.demo@gmail.com"); WebElement password = driver.findElement(By.cssSelector("input[id='pass']")); password.clear(); password.sendKeys("testing12345"); driver.findElement(By.cssSelector("input[type='submit']")).click(); Actions act = new Actions(driver); act.sendKeys(Keys.ESCAPE).

Working with Maps in Java

Image
//Map Interface has three implementations ie. HashMap, LinkedHashMap and TreeMap. //Map stores elements in key value pair. Each key and value pair is known as entry. Keys are always unique. //Retrieving of elements in HashMap is in random order of keys. //Retrieving of elements in LinlkedHashMap is in insertion order of keys. // Retrieving of elements in TreeMap is in ascending order of keys.   //Following is a sample of implementation of java HashMap public class MapExample { public static void main(String[] args) { Map mapObj = new HashMap(); mapObj.put(100, "amit"); mapObj.put(101,"Vijay");   mapObj.put(102,"Rahul");   mapObj.put(500,"Vijay");  //Here value is replaced for already existing key.   mapObj.put(99,"sumit"); mapObj.put(99,"rahul"); mapObj.put(99,"luke"); //one null key is allowed in HashMap and LinkedHashMap but not in TreeMap. mapObj.put(null,"Rahul2"); mapObj.put(n

Intern property and equals method of immutable String class in Java

Image
//String is immutable because it always creates new object in memory. String abc = "Ram";                                              //takes new memory abc = "Shyam";                                                     //takes new memory abc = "Ghanshyam";                                             //takes new memory What is String intern? String Interning is a property of storing only one copy of each distinct String Value, which must be immutable. //Now Lets explain this with example: String a1 = "cat"; String a2 = new String("cat"); String a3 = "cat"; // here (a2) reference is a new object in java memory when compared with (a1) and (a3) because we have explicitly asked java to allocate new space in memory with "new" keyword. whereas (a1) is the same object in memory and no new object is created when compared with (a3) because both of them have same content and we have no "new&

Mobile Automation Tool Appium in Android and its workflow

Image
Need of Mobile Apps Automation 1) Smart phone apps have experienced explosive growth since 2007. 2) Mobile apps are more reliable for organizations. 3) In some cases, mobile apps are the only way customers interact with their products. 4) Mobile Apps development process has become quick and efficient. What is Appium 1) Appium is an open source test automation tool developed and supported by Sauce Labs to automate native and hybrid mobile apps. It uses JSON wire protocol internally to interact with iOS and Android native apps using the Selenium WebDriver. 2) Appium server is written in Node.js and talks to android using UIAutomator driver.   Appium work flow 1. From Web-driver, Automation Commands are sent in form of  JSON via HTTP request to Appium Server.   2. Appium Server invokes Vendor specific mechanism to execute those commands on Mobile device.    3. Client sends back the message to the Appium Server.   4. Appium Server logs the result i

Creating hub and nodes on Selenium Grid manually and through automation

Image
Selenium-standalone server can act as a jar(java archive) and also server for creating hub(server) and nodes(client machines where automation will run) Pre-requistie 1. I am creating hub on my local computer on its default port(4444). 2. I am creating nodes again on local machine on port 5555 and port 5556.   3. I have places my local jar at D:\selenium-server. java -jar D:\selenium-server\selenium-server-standalone-3.141.59.jar -role hub java -jar D:\selenium-server\selenium-server-standalone-3.141.59.jar -role node -port 5555 -hub http://localhost:4444/grid/register java -jar D:\selenium-server\selenium-server-standalone-3.141.59.jar -role node -port 5556 -hub http://localhost:4444/grid/register Now instead of creating manually, I am using java program and doing it programatically. (making use of java runtime class) *************************************************************************************** QACult Best Software Testing Courses in Chandigarh trici

Implementation of methods in Interfaces with static and default keyword

Image
Defining default method in interface  - Java 8 allows implementation of methods in interface which are otherwise abstract. This is possible with keyword ' default ' before methods. They are added to the interface to provide additional functionality to all implementing classes without requiring them to define the method. Defining static methods in interface  - Java 8 also allows to provide implementation of static methods in interface. Otherwise it is not possible to declare static methods in interface because in interface all the methods are abstract implicitly.Since static methods don’t belong to a particular object, they have to be called by using the interface name. Please see this with following example: public interface NewIF { default public void social() { System.out.println("I am default method from interface"); } public void operate(); public void calculate(); public static void enquire() { System.out.println("I am static enquiry from inter

XPath Locator using (contains), text property of element and finding xpath for child at any level of parent.

Image
using 'contains' in xpath Lets try to find xpath locator of new button in above shown picture. 'New' button has attribut ' id ' with value ' menubutton19 '. Now ' 19 ' seems to be number which may change. So lets take substring of value and use ' menubutton '  ie substring of complete value. The xpath of above element can be created by using the contains keyword which has the syntax   contains(@attribute,'value')   and xpath becomes  //tagname[contains(@attribute,'value') ] which is    //button[contains(@id,'menubutton') Now this is not unique. Locating child element at any level(//) and using text property of element in xpath There is one element ' span ' located  inside the 'button'  element which has 'text' property ' New '. We can use this text property to uniquely find the element.  Here we will use  (//)  in xpath to tell xpath locator that element is an

Is Selenium with Java automation testing a better career option now?

Image
Hi, When was this not a good option.  Java is a complete and secure language and most of the companies are still using selenium with java because java is most accptable and useful language. In Java you can create any kind of utility and integrate it with your selenium framework. Also after learning OOPS in java language, one can develop selenium framework in any other language too like python, ruby, javascript, php etc because meaning of OOPS is same in every language. But this is not vice-versa. I can give you my example, I am actually a java person but have developed selenium-frameworks in python, ruby, javascript, php too. So selenium with java is always a good option and is not going anywhere. It has already captured most of the market. *************************************************************************************** QACult Best Software Testing Courses in Chandigarh tricity .- We love to enhance your knowledge. QACult is the premier institute catering