Useful links to learn Automation (updating)

These are my favorite web sites:

  1. https://www.guru99.com/
  2. http://toolsqa.com/
  3. https://www.udemy.com

suggestions:

Guru99 Java Tutorial for Beginners

Selenium WebDriver With Java – Novice To Ninja + Interview

Guru 99 Selenium Tutorials

Appium tutorial

 

 

 

Advertisements

[ERROR] COMPILATION ERROR when running maven test

Problem: Error below is shown during run maven test:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.424s
[INFO] Finished at: Tue Oct 29 15:21:01 IST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler- plugin:3.1:compile (default-compile) on project TEST-WEB: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Solution:

On your Eclipse IDE, go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.

Eclipse_IDE

Control Panel > Java > Java Control Panel > Java > View > change to jdk.

java
Then Right-Click on your Project -> Maven -> Update Project

 

Generate/search cssSelector and Xpath on Firefox 55 onward

As you know, Firebug extension is no long working on Firefox 55 and later. The latest version of Firebug is 2.0.19 which compatible with Firefox 30 – 54. So you may want to install the old Firefox build 54 , disable auto update and happy with the latest Firebug.

But it is quite inconvenience. So I will share you 2 tools that we can do the same functionalities of Fire Bug such as : inspect Element, generate css Selector or xpath of element, search an element using css/xpath…

The first tool is Firefox DevTools .This is the tool suggested by http://www.getfirebug.com .

“The Firebug extension isn’t being developed or maintained any longer. We invite you to use the Firefox DevTools instead, which ship with Firebug.next”

generate locator

How to use Firefox Developer tool:

  • Press F12 or right click on element and select “Inspect Element”.
  • Click icon pickE  to pick an element from the page. Then you can right click on Element in Inspector tab and select Copy (CSS Selector, XPath ) as you see in the screenshot above. however the XPath generated here is absolute XPath . so it is not useful for me.
  • Search Element using css selector: Firefox Dev tool only allows us to search an element using CSS Selector. searching an Element using XPath is not supported yet. There is an enhancement S2 for this Bug 963933 . I hope they will add this feature soon.

XPath locator is very important for us. It is quite handy to handle some elements which there is no ID and cssselector cannot help. you have to do an XPath search, then walk up the DOM, then back down to get to the element you want.

Fortunately , there is another extension on Firefox can help us to generate and search xpath locator. It is AutoPager.

(this add-on also help to generate xpath: https://addons.mozilla.org/en-us/firefox/addon/element-locator-for-webdriv/)

AutoPager

How to use AutoPager Extension:

  • Generate xpath of Element: right click on Element on the web page, select Auto Pager >XPath Utils > Create xpath. It will show the AutoPager window. you can get the xpath in Link XPath field. It also have a list of possible xpath and the number of match found. Make sure you select the one which have only one match found for your testing. You also can click on find button pick and pick an element on web page to generate xpath for it.
  • Search xpath:  This is the feature that i use frequently . it is very handy. You can define your own xpath and paste it into Link XPath and enter to check if there is any element match with your defined xpath. Click … on the right of Link Xpath field, it will show you all functions used to define an xpath. I love it.  When you search xpath , make sure you are on the correct Frame.

 

copyxpath_AutoPager
XPath Utils
generate xpath of element
Generate an Xpath for Element
XPath Expression
XPath Expression: help us to define Xpath
Frame

Handle Native Windows upload popup using Robot and Clipboard class

When we click on upload button on a web page, an native windows popup will be displayed and we need to give the path to the file we want to upload. Selenium WebDriver cannot handle this popup.

There are two solutions for this scenario.

  1. Using Java Robot and Clipboard classes to simulate copy and paste action. we can paste the file path in the popup window and simulate enter key event.
  2. Using AutoIT tool to handle the pop up.

In this post, I will show you how to handle windows upload popup using the first solution.

1. import these class into your test script:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

2. Create instance of Robot class and Clipboard class
Robot robot = new Robot();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

3. use StringSelection to cache the upload file path string.

StringSelection filepath = new StringSelection(“F:\\DOCUMENT\\SELENIUM\\myCV.doc”);

4. Copy the file path to Clipboard

clipboard.setContents(filepath , null);

5. Use Robot class to simulate CTRL+C and CTRL+V key events :

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

below is full script to send an email with attachment:

gmail_upload

package mypacket;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.awt.Toolkit;

public class SendGmailwithRobot {
 WebDriver driver;
 String baseURL;

@BeforeTest
 public void beforeTest() {
 System.setProperty("webdriver.gecko.driver", "F:\\SOFTWARE\\Automation\\geckodriver.exe");
 baseURL = "https://www.google.com/gmail/about/";
 driver = new FirefoxDriver();
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
 driver.get(baseURL);
 }

@Test
 public void sendGmail() throws InterruptedException, AWTException {
 driver.findElement(By.linkText("Sign In")).click();
 driver.findElement(By.id("identifierId")).sendKeys("yourgmail@gmail.com");
 driver.findElement(By.cssSelector("span.RveJvd")).click();
 Thread.sleep(3000);
 driver.findElement(By.id("password")).sendKeys("your gmail password");
 driver.findElement(By.id("passwordNext")).click();
 driver.findElement(By.xpath("//div[text()='COMPOSE']")).click();
 driver.findElement(By.xpath("//div[@class='wO nr l1']//textarea")).sendKeys("destinationemail@gmail.com");
 driver.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys("email title here");
 WebElement attachbt = driver.findElement(By.xpath("//div[@class='a1 aaA aMZ']"));
 attachbt.click();

Robot robot = new Robot();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection filepath = new StringSelection("F:\\DOCUMENT\\SELENIUM\\myCV.doc");
clipboard .setContents(filepath, null);

 robot.keyPress(KeyEvent.VK_CONTROL);
 robot.keyPress(KeyEvent.VK_V);
 robot.keyRelease(KeyEvent.VK_V);
 robot.keyRelease(KeyEvent.VK_CONTROL);
 robot.keyPress(KeyEvent.VK_ENTER);
 robot.keyRelease(KeyEvent.VK_ENTER);

driver.findElement(By.xpath("//div[text()='Send']")).click();
 }

@AfterTest
 public void afterTest() {
 driver.close();
 }
}

 

Linux tips for Automation

1. How to Keep Your SSH Sessions Alive

Login as root and change two settings below:

$vi /etc/ssh/sshd_config
ClientAliveInterval 0
#ClientAliveCountMax 3

ClientAliveInterval:
number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive). This is the limit of how long a client are allowed to stay unresponsive before being disconnected. Setting a value of 0 (the default) will disable these features so your connection could not be dropped if it is idle too long.

ServerAliveCountMax
Sets the number of server alive messages (see below) which may be sent without ssh(1) receiving any messages back from the server. If this threshold is reached while server alive messages are being sent, ssh will disconnect from the server, terminating the session.
you can run $man sshd_config to read more details about these settings.

Another example:
/etc/ssh/sshd_config:
ClientAliveInterval 300
ClientAliveCountMax 2

These settings will make the SSH client or server send a null packet to the other side every 300 seconds (5 minutes), and give up if it doesn’t receive any response after 2 tries, at which point the connection is likely to have been discarded anyway.

 

2. Running  a command with sudo without entering password.

[admin@Thachsystem ]$ sudo /usr/share/hnthach/install_build.sh

for example, i want to run the script above in admin user. There are some commands in that script required sudo. So to run it , I need to do the following steps:

– Create the file installation in  /etc/sudoers.d/ directory.

–  Add one line to installation file:

[admin@Thachsystem ]$ sudo visudo -f /etc/sudoers.d/installation
%admingrp ALL=(ALL) NOPASSWD:/usr/share/hnthach/install_build.sh

the syntax is:  %groupname host = (user privileges ) NOPASSWD: /sbin/shutdown

admingrp is group name, this means that all member of the admingrp group will run this command using sudo without a password.

You can also use /etc/sudoers  instead of modifying /etc/sudoers.d. But i would prefer sudoers.d.  This is good way to separate customized changes to sudo rights and leaves the original sudoers file untouched.

 


 

 

Jmeter – Share cookie across thread groups

Objectives:  Get cookie data from the request in first thread group, store it to csv file. so requests in other thread groups can use that cookie.

Requirement:

  • Create new csv file. It needs to be clean up before running test suite.
  • Extract cookie data from thread group , save it as variables and store them to csv file.
  • In other thread group, fetch data from csv file and save them as variables. Then Insert cookie to the request.

Solutions:

  1. create new csv file:

Manually create a new csv file. Eg : D:\DailyRun\Jmeter\cookievar.csv

  1. Clean up csv file before getting and writing cookie into it. Otherwise, multiple values will append to csv file and it causes wrong cookie inserted to requests in other groups.

Use BSF Sampler to execute the command: 

exec(“cmd.exe /C D:\\thachhoangngoc\\deleteCSV.bat”);

This bat file contains commands to copy fresh file and overwrite the old one.

echo Delete cookievar.csv

copy /Y D:\thachhoangngoc\cookievar.csv D:\DailyRun\Jmeter\cookievar.csv

(Actually, this is a work around. I couldn’t find a solution to clean up csv file directly in Jmeter. I tried method  file.clear() in Beanshell script but it didn’t work.)BSF Sampler

  1. extract cookie data from first request. cookie will be generated in first request. You can find cookie data in response header.

Use Regular Expression Extractor to extract cookie data and save it to variables. In this example, cookie data contains JSESSIONID and JSESSIONIDSSO. So I added two regular expression Extractor.Regular Expression Extractor1Regular Expression Extractor2

  1. write two cookie variables to csv file.

Use BeanShell PostProcessor. File path here is D:\DailyRun\Jmeter\cookievar.csv.beanshellPostProcessor

  1. fetch cookie data from csv file in other thread groups:CSV data set config

Insert cookie into request using  BeanShell PreProcessor.

 InsertCookieusing BeanshellPreProcessorTestPlanJMX

 

 

 

 

 

 

 

 

 

 

 

 

Software QA Quotes

Below are my favorite quotes related to Software Quality Assurance. some of them are funny 🙂

  • “In God we trust, and for everything else we test.— this is my favorite one.

  • “Trust, But Verify”

  • “The only certainties in life are death, taxes and bugs in code”

  • “All code is guilty, until proven innocent”

  • “Life is too short for manual testing”

  • “No amount of testing can prove a software right, a single test can prove a software wrong.”— Amir Ghahrai

  • “To an optimist, the glass is half full. To a pessimist, the glass is half empty. To a good tester, the glass is twice as big as it needs to be.”

  • “The bitterness of poor quality remains long after the sweetness of meeting the schedule has been forgotten.”

  • “You can be a great tester if you have programming skills. You can also be a great tester if you have no programming skills at all. And, you can be a lousy tester with or without programming skills. A great tester will learn what skills she needs to continue to be great, in her own style.”— Jerry Weinberg

  • “More than the act of testing, the act of designing tests is one of the best bug preventers known. The thinking that must be done to create a useful test can discover and eliminate bugs before they are coded – indeed, test-design thinking can discover and eliminate bugs at every stage in the creation of software, from conception to specification, to design, coding and the rest.” – Boris Beizer

  • “You must be a constructive schizophrenic. Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer’s software. The tester in you is your Mr. Hyde – your Incredible Hulk. He must exercise what Gruenberger calls ‘low cunning.” – Boris Beizer

  • “The Definition of an Upgrade: Take old bugs out, put new ones in”

  • “Blame doesn’t fix bugs.”

  • “Fast, good, cheap: pick any two.”

  • “Lots of methodologies have come and gone, paradigms have changed but the requirements are always the same; Make it good and make it fast.”

  • “Discovering the unexpected is more important than confirming the known.“— George E. P. Box

  • “I do believe it’s important for testers to know the market that their client or their employer is in and the reason for that is if you understand what risks your client is facing and you understand what the competing products are and where the challenges lie in the market, you can plan your testing accordingly.”— Karen N. Johnson

  • “It’s not at all important to get it right the first time. It’s vitally important to get it right the last time.”— Andrew Hunt and David Thomas

  • “Walking on water and developing software from a specification are easy if both are frozen.”— Edward V. Berard

  • “Software and cathedrals are much the same: first we build them, then we pray.”

  • “Just like with everything else, tools won’t give you good results unless you know how, when, and why to apply them. If you go out and you buy the most expensive frying pan on the market it’s still not going to make you a good chef.”— Christin Wiedemann

  • “I remember the days when QA testers were treated almost as second-class citizens and developers ruled the software world. But as it recently occurred to me: we’re all testers now.” —Joe Colantonio

  • “Only conducting performance testing at the conclusion of system or functional testing is like conducting a diagnostic blood test on a patient who is already dead.”— Scott Barber