Steps to Launch the ChromeBrowser without using chromedriver.exe



Selenium WebDriver automation tool is mainly useful to run tests against multiple Browsers such as Chrome Browser,Firefox Browser,Internet Explorer Driver.Running the tests against multiple browsers is known as Cross Browser Testing.
To launch the Browser in Selenium WebDriver we need to set the path of the executable available in the laptop. Following that we have to instantiate the driver instance based on the Driver instance. In order to avoid these steps we can use the WebDriverManager class.

WebDriverManager

WebDriverManager allows to automate the management of the binary drivers (e.g. chromedriver, geckodriver, etc.) required by Selenium WebDriver.
Using WebDriverManager its not required to maintain the below lines of the code for launching the browser.
System.setProperty(“webdriver.chrome.driver”, “/path/to/binary/chromedriver”);
System.setProperty(“webdriver.gecko.driver”, “/path/to/binary/geckodriver”);
System.setProperty(“webdriver.opera.driver”, “/path/to/binary/operadriver”);
System.setProperty(“phantomjs.binary.path”, “/path/to/binary/phantomjs”);
System.setProperty(“webdriver.edge.driver”, “C:/path/to/binary/MicrosoftWebDriver.exe”);
System.setProperty(“webdriver.ie.driver”, “C:/path/to/binary/IEDriverServer.exe”);

WebDriverManager Maven Depdendency

To use the WebDriverManager class ensure the following depedency is added in the maven project object model (pom.xml) file.


Like our Facebook Page to get frequent updates->

https://www.facebook.com/totalqa


Selenium WebDriver Code

Execute the below code in eclipse and verify the results.

Capturing screenshot using java.awt.Robot class-Selenium WebDriver



The java.awt.Robot class is mainly useful to perform native actions where keyword and mouse actions to be performed. This actions are helpful for automation. If the current platform configuration does not allow input controls, an AWTException will be thrown when using the java.awt.Robot class. In this post we will java.util.Robot class for capturing the screenshots. The method createScreenCapture(Rectangle screenRect) is available in java.awt.Robot class which helps to create an image containing pixels read from the screen.The java.awt.Rectangle object to be passed as an parameter for capturing the screenshot. To create an Rectangle object the java.awt.Dimension[Height*Width] object to be passed as an parameter.

API Classes and Methods useful to capture the Screenshot as follows:

  • Robot Class Object
  • Rectangle Class Object
  • Dimension Class Object- Input Parameters Height * Width

Selenium WebDriver Code

Output:

The full screen is captured as screenshot which is the expected outcome as shown below:

Capture Screenshot using java.awt.Robot Class

Capture Screenshot using java.awt.Robot Class

Regex Pattern Matching in JAVA – String Functions startsWith(),endsWith(),contains()



To identify particular pattern of regular expressions in Strings is achieved in JAVA by using the API java.util.regex. This API consists of two main java classes such as Matcher and Pattern classes. Also we can even use String Functions to identify the particular pattern of regular expressions in the String class.

Pattern Class

A regular expression specified as a String is passed into an instance of this class.
The output is used to create a Matcher object that can match the character sequences against the regular
expression.

Static methods available in the Pattern Class as follows:

  • pattern()
  • split()
  • matcher()
  • compile()
  • matches()

Matcher Class

This java class helps to matches the character sequences by interpreting the pattern.

Static Matcher Methods in the API:

  • start()
  • end()
  • group()

Identify the List of Strings Starts with a particular letter

Output of the Program:

Result:: false
Result:: false
Result:: false
Result:: true
Start index: 0 End index: 1 Group value::t


String Functions to identify the Regular Expressions:

  • startsWith(String prefix)
  • endsWith(String suffix)
  • contains(CharSequence s)

Identify the List of Strings Starts with a particular letter using String Functions

Output of the Program:

String starts with a particular character:::total-qa
String starts with a particular character:::tutorialpoint
String ends with a particular character:::guru99
String contains with a particular character:::total-qa
String contains with a particular character:::javatpoint
String contains with a particular character:::tutorialpoint


Conclusion:

Using the String functions and java.util.regex API, identification of the pattern in the given Strings is possible using the above examples.

Add,Remove,Update – ArrayList,LinkedList,Vector Mock Interview Questions



List is a type of Collection mainly useful to store the Objects which are duplicates as well. Its available in the package java.util.List. The behavior of the List is implemented by the java classes

  • ArrayList
  • LinkedList
  • Vector

Java Mock Interview Questions about java.util.List as follows:

1. Adding an new item to the List
2. Adding an new item first to the List.
3. Adding an item from in the middle of the List.

4. Remove an item from the List.
5. Remove an item from the List at particular index.
6. Update an item from the List.

Conclusion:

Addition,Deletion and Updating the items of List is achieved using the methods available in the java.util.List package.

Dynamic Input Test Data Generation: Best Practices,Random Java API



In Testing it is important to provide input data to complete the execution of Test-cases. Irrespective of any type of testing such as Functional Testing,Integration Testing,System Testing and Performance Testing the input data plays a vital role.
In Automation tools such as Selenium WebDriver the input data can be maintained in three different ways:

1. Maintain parameters in the testng.xml. Read the parameter values using @Parameters annotation.
2. Maintain input data in the Excel File. Read the data and pass the values using @DataProvider annotation.
3. Input Data in the properties file.

In the above 3 cases, the input data stored is static. If we suppose, the dynamic data should be generated used in the execution flow of test cases. We have to Java API to generate the dynamic data.
So, we will go through now how to generate the random/dynamic input data.

Note:
Do not get confuse with the dynamic object properties. In this post we are discussing about only the input data.

Generating two digit Random Number

java.util.Random is a java class available for generating random integers.

Generating three digit Random Number

Generating Random ASCII Character

To generate the random characters we should glance through the ASCII table from this link.
http://www.asciitable.com/

      Lower Case Alphabets– Decimal Number Ranging from 97 to 122
      Upper Case Alphabets– Decimal Number Ranging from 65 to 90

Generating five digit Random Number

Conclusion:

The Dynamic input data generated is useful to execute the test case in different Testing Environment without any dependency on resource files.

Selenium IDE Recording and Playback – Get this Extension for Chrome



Selenium IDE is one of the important Component of Selenium. IDE stands for Integrated Development Environment useful for Record and Playback and helps for getting acquainted with Selenium Web-Driver.
The new version Selenium IDE is designed to record and playback interactions with different browsers such as ‘Mozilla Firefox’ and ‘Chrome‘.

Steps for downloading IDE on Firefox Browser(Pre-requisite – Firefox)

1. Download the Mozilla Firefox by accessing the link ->https://www.mozilla.org/en-US/firefox/new/

2. Access Firefox and open the URL http://seleniumhq.org.

3. Navigate to Download tab look for Selenium IDE.

4. Download latest released version of Selenium IDE for Firefox by clicking on the Link Firefox which redirects to the url ->
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/

Steps for downloading IDE on Chrome Browser(Pre-requisite – Chrome)

1. Download the Chrome Browser by accessing the link ->https://www.google.com/chrome/

2. Access Firefox and open the URL http://seleniumhq.org.

3. Navigate to Download tab look for Selenium IDE section.

4. Download latest released version of Selenium IDE for Firefox by clicking on the Link Firefox which redirects to the url ->
https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd

Record and Playback the Scripts on Chrome Browser:

1. Open Selenium IDE.

Selenium IDE - Chrome Browser

Selenium IDE – Chrome Browser


2. Click on the link Record a new test in a new project.
Selenium IDE - Record a new test in a new project

Selenium IDE – Record a new test in a new project

3. Provide the project name and click on OK button.

Selenium IDE Project Name

Selenium IDE Project Name

4. Provide the Base URL and click on START RECORDING button.

Base URL -> http://www.seleniumhq.org

Base URL -> http://www.seleniumhq.org

5. A new Chrome browser opens with the Base URL. Perform the steps and check the recorded steps in the background.
Click on Stop Recording button in Selenium IDE to complete Recording.

Selenium IDE - Recording and playback on  Chrome Browser

Selenium IDE – Recording and playback on Chrome Browser

Conclusion:

Selenium IDE add-on helps us to record the steps on Chrome Browser as well.
It also helps us to identify the properties of the Web-Elements available in the Web Application.

How to use Selenium Grid easily in 3 Steps?

      No Comments on How to use Selenium Grid easily in 3 Steps?


Selenium-Grid allows you run your tests on remote desktop against different Operating Systems like Windows,Linux,MAC and against different browsers like Opera,Safari,IE,Firefox and Chrome in parallel. Selenium-Grid allows running your tests in a distributed test execution environment.


Grid Architecture:

In Selenium-Grid, the Component Hub acts as a server receives the requests from Selenium WebDriver program and redirects requests to the Nodes which are configured to Hub. Refer to the details in the diagram mentioned below:

Grid Architecture

Grid Architecture


Installation:

Ensure the Selenium Standalone Server Jar is downloaded in Hub and Node Systems as well.
Download the Selenium Standalone Server Jar from this link -> http://selenium-release.storage.googleapis.com/index.html


Starting Hub:

The Hub is the central point that will receive all the test request and distribute them the the right nodes.
Open the new command line and execute the below command:
java -jar selenium-server-standalone-xxx.jar -role hub -port 4545


Starting Node 1:

Use the same http://selenium-release.storage.googleapis.com/index.html jar file to start the nodes and connect to the Hub.
Capabilities for Node 1:

  • Platform : WINDOWS
  • Browser Name: firefox
  • Browser Version:123

Open the new command line and execute the below command:


java -Dwebdriver.gecko.driver=”C:\\XXXX\\geckodriver-v0.23.0-win64\\geckodriver.exe”
-jar selenium-server-standalone-3.141.59.jar
-role webdriver
-browser “browserName=firefox,version=123,maxInstances=1,platform=WINDOWS”
-hubHost localhost
-hubPort 4444
-port 4546


Starting Node 2:

Use the same http://selenium-release.storage.googleapis.com/index.html jar file to start the nodes and connect to the Hub.
Capabilities for Node 2:

  • Platform : WINDOWS
  • Browser Name: chrome
  • Browser Version:40

Open the new command line and execute the below command:


java -Dwebdriver.chrome.driver=”C:\\XXXX\\chromedriver_win32\\chromedriver.exe”
-jar selenium-server-standalone-3.141.59.jar
-role webdriver
-browser “browserName=chrome,version=40,maxInstances=1,platform=WINDOWS”
-hubHost localhost
-port 4547


Selenium WebDriver Testng Program:


Results:


To check the ports which are reserved

To verify that the port number 4444 is in use. Execute the below command in the command line:
netstat -a -n | findStr 4444

Conclusion:

Selenium Grid is useful to run test cases remotely with specific capabilities.

[CSS Tips]white-space-hyphen-minus selenium

      No Comments on [CSS Tips]white-space-hyphen-minus selenium


In this tutorial we will discuss about the identifying the Selenium Locator for the Css (Cascading Style Sheets) in the following scenario’s

  • white spaces in an Web Element attribute value
  • hyphen-minus (-) in an Web Element attribute value
  • Attribute Selector
  • Type Selector


HTML Source Code for a Text-box having spaces for attribute id value:

Represents an element with the attribute whose value is a white space-separated list of words, one of which is exactly “val”.
id="pass word".

Syntax:

[att~=val]

Examples:

[id~=pass]
[id~=word]

Selenium Locators-Css white space

Selenium Locators-Css white space


HTML Source Code for a Text-box having hyphen-minus for attribute id value:

id="pass-word".

Syntax:

Represents an element with the attribute, its value either being exactly “val” or beginning with “val” immediately followed by “-”
[att|=val]

Examples:

[id|=pass]

Css attribute value having hyphen-minus special character

Css attribute value having hyphen-minus special character


Attribute Selector:

Match when the element sets the “att” attribute, whatever the value of the attribute.

Example:

[id] – Selects all the Elements having ‘id’ attribute.
[type]- Selects all the Elements having ‘type’ attribute.

Css Locator - identify all the elements having <id> as attribute

Css Locator – identify all the elements having type as attribute

Type Selector:

Matches every instance of element Type.

Example:

h1 – Selects all the elements having h1 as tag-name.
input- Selects all the elements having input as tag-name.

Type Selector in CSS

Type Selector in CSS

Conclusion:

In this topic we have discussed about Handling CSS attribute values from Selenium Web-driver perspective which are having white spaces and special characters hyphen-minus (-).

[Solved]SessionNotCreatedError: Unexpected error launching Internet Explorer



In this tutorial we will discuss about Fixing the issues that arises during execution of Selenium WebDriver tests against the browser Type Internet Explorer. Before Running Tests, make sure the following settings are updated for the Internet Explorer.

Browser Zoom Level

Access File Menu->View->zoom should be set to 100%.

Protected Mode Settings

Access File Menu->Tools-> Internet Options->Security.
Make sure the Protected Mode is enabled or disabled for all the Security Zones as listed below:

  • Internet Zone
  • Local intranet
  • Trusted Sites
  • Restricted Sites
Enabled or Disable Protected Mode

Enabled or Disable Protected Mode

Executable File

Add the IEDriverServer.exe to the eclipse project by downloading from the link https://www.seleniumhq.org/download/

Untrusted SSL Certificate

To Handle the SSL Certificates on IE Browsers use the following code snippet to Handle SSL Certificates. This logic clicks on the link Continue to this website(recommended)

driver.navigate().to(“javascript:document.getElementById(‘overridelink’).click()”);

Selenium WebDriver Program:

Conclusion

Therefore, setting the zoom to 100% and enabling or disabling the protected mode for all the security zones resolves the SessionNotCreatedError.

Software Testing Interview Questions

      1 Comment on Software Testing Interview Questions


Software Testing Interview Questions
In this article, we see best interview questions of Software Testing. Let’s get started.

What is Test Harness?
A test harness is the collection of software and test data configured to test a program unit by running it under varying conditions which involves monitoring the output with expected output.

What is Integration Testing?
Integration Testing is the process of testing the interface between the two software units. Integration testing is done by three ways. Big Bang Approach, Top Down Approach, Bottom-Up Approach

What is Adhoc Testing?
Ad-hoc testing is quite opposite to the formal testing. It is an informal testing type. In Adhoc testing, testers randomly test the application without following any documents and test design techniques. This testing is primarily performed if the knowledge of testers in the application under test is very high. Testers randomly test the application without any test cases or any business requirement document.
What are the principles of Software Testing?
1. Testing shows presence of defects
2. Exhaustive testing is impossible
3. Early testing
4. Defect clustering
5. Pesticide Paradox
6. Testing is context depending
7. Absence of error fallacy

What is Defect clustering?
Defect clustering in software testing means that a small module or functionality contains most of the bugs or it has the most operational failures.

What is Pesticide Paradox?
Pesticide Paradox in software testing is the process of repeating the same test cases, again and again, eventually, the same test cases will no longer find new bugs. So to overcome this Pesticide Paradox, it is necessary to review the test cases regularly and add or update them to find more defects.

What is Bug Leakage?
A bug which is actually missed by the testing team while testing and the build was released to the Production. If now that bug (which was missed by the testing team) was found by the end user or customer then we call it as Bug Leakage.

What is Showstopper Defect?
A showstopper defect is a defect which won’t allow a user to move further in the application. It’s almost like a crash.
Assume that login button is not working. Even though you have a valid username and valid password, you could not move further because the login button is not functioning.

What is State Transition?
Using state transition testing, we pick test cases from an application where we need to test different system transitions. We can apply this when an application gives a different output for the same input, depending on what has happened in the earlier state.

What is Defect Age?
Defect age can be defined as the time interval between date of defect detection and date of defect closure.
Defect Age = Date of defect closure – Date of defect detection
Assume, a tester found a bug and reported it on 1 Jan 2016 and it was successfully fixed on 5 Jan 2016. So the defect age is 5 days.

If you have any queries, please comment below.

Author bio: Rajkumar SM is a founder of SoftwareTestingMaterial.com. He is a certified Software Test Engineer. He has an extensive experience in the field of Software Testing.