Thursday, March 10, 2022

Selenium Commands Cheatsheet


 

Selenium 4


 New Features and Updation in Selenium 4:

1. Selenium is now W3C compliant:

  • JSON wire protocol was used to communicate between the SE Webdriver API's and the browser native APIs
  • With W3C compliance. the communication happens directly without any encoding and decoding required
  • Any software following W3C standard protocol can be integrated with Selenium with no compatibility issues

2. Relative Locators:

  • Function to locate nearby elements by specifying directions
  • Existing locator strategy        

3. Better Window and Tab Management:

  • Work with multiple windows or tabs in the same session
  • Can now open multiple windows and tabs without creating a new driver object

4. Improved Selenium Grid:

    Selenium Grid helps in Distributed Test Execution
  • Enables test execution on different combinations of browsers, OS, and Machines
  • Enables parallel execution
    Selenium Grid is now redesigned

    Docker support
    Enables to spin up the containers. (No need to set up VMs)
    Enables to deploy the grid on Kubernetes for better scaling

    Easier Management - No need to set up and start hubs and nodes separately

    3 ways to run Se Grid

    Standalone Mode
    Hub and Node
    Distributed

    a. Standalone Mode:

    The new Selenium Server Jar contains all the functionalities needed to run a grid
                       java -jar selenium-server-4.0.0.jar standalone
   The Grid automatically identifies that the WebDriver for Chrome and Firefox are present on the system

    b. Hub and Node:

    The classical way of using the Grid for selenium test Automation consists of two major components i.e. Hub and Node
        start hub:             java -jar selenium-server-4.0.0.jar hub
        register node:      java -jar selenium-server-4.0.0.jar node --detect-drivers

    c. Distributed:

        Grid 4 can be started in a fully distributed manner, with each piece running in its own process
        Selenium Grid 4 consists of four processes: 
        Router,
        Distributor, 
        Session and 
        Node

5. Upgraded Selenium IDE:

        Record and Playback tool
        Available as an add-on - Firefox, Chrome, and MS Edge
    • More stable and reliable            
    • Improved GUI
    • SIDE runner - Se IDE runner for CMD execution, grid, and node projects
    • Better element locator strategy

6. New APIs for CDP (Chrome DevTools Protocol): 

        Chrome DevTools - Set of tools built directly into chromium-basedbrowsers like chrome, Opera, and Microsoft Edge to help developers to debug and investigate the websites
    • Inspects element in the DOM
    • Edit elements and CSS on the fly
    • Check and monitor the site's performance
    • Mock Faster/Slower network's speeds
    • Mock geolocations of the Users
    • Execute and debug JavaScript
    • View console logs
    • Se 4 comes with native support for Chrome DevTools API
    • Capture and monitor the network traffic
    • Simulate poor network conditions
    • Perform geolocation testing
    • Change device mode to do responsive design testing
    new ChromiumDriver class, which includes two methods to access chrome devTools
    1. getDevTools()
    2. executeCdpCommand()  

7. Deprecations of Desired Capabilities:

    Desired Capabilities were primarily used in the test scripts to define the test environment (browser name, version, and operating system) for execution on the Selenium Grid
    Capabilities objects are replaced with options:
    • Firefox - FirefoxOptions    
    • Chrome - ChromeOptions
    • IE - InternetExplorerOptions
    • Microsoft Edge - EdgeOptions
    • Safari - SafariOptions
    Cloud-based Selenium Grid setup

        ChromeOptions options = new ChromeOptions();
        options.setAcceptInsecureCerts(true);
 
        options.setCapability("build", "Testing Chrome Options [Selenium 4]");
        options.setCapability("name", "Testing Chrome Options [Selenium 4]");
        options.setCapability("platformName", "Windows 10");
        options.setCapability("browserName", "Chrome");
        options.setCapability("browserVersion", "latest");

7. Modifications in the Actions class: 

    Actions class in Selenium is used to simulate input actions from mouse and keyboard on specific web elements (e.g. Left Click, Right Click, Double Click etc)












Monday, May 24, 2021

 My First AWS Instance:


My First RDP Machine in AWS:


If you need any help to instantiate the RDP with running instances ...

Wednesday, May 12, 2021

Tuesday, May 4, 2021

Kindly contact for online software testing courses by video conference.

Courses Available For Engineering Students:

  1. Software Manual Testing

  2. Software Automation Testing

  3. Selenium WebDriver

  4. Core Java

  5. BrowserStack, Mailinator, Jenkins, Jira, TestRail, and other testing related tools

    Kindly contact: 1feb1986@gmail.com

    You can use the contact form for any query.

    Thanks: Prashant Chauhan

 General Principles of Testing:

===================

  • Principle 1: Testing shows the presence of defects, not their absence.

Testing can show that the product fails, i.e., that there are defects. Testing cannot prove that a program is defect-free. Adequate testing reduces the probability that hidden defects are present in the test object. Even if no failures are found during testing, this is no proof that there are no defects.

 

  • Principle 2: Exhaustive testing is impossible.

It’s impossible to run an exhaustive test that includes all possible values for all inputs and their combinations combined with all different preconditions. Software, in normal practice, would require an “astronomically” high number of test cases. Every test is just a sample. The test effort must therefore be controlled, taking into account risk and priorities.

 

  • Principle 3: Testing activities should start as early as possible.

Testing activities should start as early as possible in the software life cycle and focus on defined goals. This contributes to finding defects early.

 

  • Principle 4: Defect clustering. Defects are not evenly distributed; they cluster together.

Most defects are found in a few parts of the test object. Thus if many defects are detected in one place, there are normally more defects nearby. During testing, one must react flexibly to this principle.

 

  • Principle 5: The pesticide paradox. Insects and bacteria become resistant to pesticides.

Similarly, if the same tests are repeated over and over, they tend to lose their effectiveness: they don’t discover new defects. Old or new defects might be in program parts not executed by the test cases. To maintain the effectiveness of tests and to fight this “pesticide paradox,” new and modified test cases should be developed and added to the test. Parts of the software not yet tested, or previously unused input combinations will then become involved and more defects may be found.

 

  • Principle 6: Testing is context-dependent.

Testing must be adapted to the risks inherent in the use and environment of the application. Therefore, no two systems should be tested in the exactly same way. The intensity of testing, test exit criteria, etc. should be decided upon individually for every software system, depending on its usage environment. For example, safety-critical systems require different tests than e-commerce applications.

 

  • Principle 7: No failures mean the system is useful is a fallacy.

Finding failures and repairing defects does not guarantee that the system meets user expectations and needs. Early involvement of the users in the development process and the use of prototypes are preventive measures intended to avoid this problem.

 

#HappyLearning

Wednesday, October 9, 2019

How to work with Test Fairy links to upload the build in browser stack ?



When you get the test fairy mail for installing any build on browser stack then follow below rules:


  • Open the Test Fairy mail
  • Click on the install app link like Click Here
  • One url will open like "https://my.testfairy.com/download/74R32C9K70TJTD1J68W38DHN6DVQ0PMW1V3AFVVND4RYFYHSWPNY5DSC/getapp?_=1569570891"
  • Delete the url from backward till /getapp like "https://my.testfairy.com/download/74R32C9K70J68W38DHN64SJV6DVQ0PMW1V3AFVVND4RYFYHSWPNY5DSC/"
  • Add install.plist text on same place like "https://my.testfairy.com/download/74R32C9K70TJTD1J68W38DSJV6DVQ0PMW1V3AFVVND4RYFYHSWPNY5DSC/install.plist"
  • And submit the url
  • Copy the ipa String url from new xml page like: <string>https://d3bgf4y6nbjwg6.cloudfront.net/73673/8e8a67153d2abe619f6b7bdb03fc2a4c12a1e9c9/ApplicationName.ipa </string>
  • Open this ipa url to browser and get the submit button then one build will be saved in your system
  • Then upload this build to the browser stack and you will be ready to test the build


Wednesday, June 21, 2017

How to log off the Virtual Machine without any services interruption on the same?

I was working with the VM and always my pulse secure connection was disconnected hence my application was down, So I got the batch file which is logging off the system properly without disconnecting the VPN connection. 

The batch job text is written below:

========================================

@ECHO OFF
C:\Windows\System32\tscon.exe rdp-tcp#0 /dest:console 
C:\Windows\System32\tscon.exe rdp-tcp#1 /dest:console 
C:\Windows\System32\tscon.exe rdp-tcp#2 /dest:console 
C:\Windows\System32\tscon.exe rdp-tcp#3 /dest:console 
C:\Windows\System32\tscon.exe rdp-tcp#4 /dest:console

========================================

And Save the above text as any bat file like "SoftLogOff.bat" and save in the VM system.

While logging off you should double-click on this bat file and then the system will be logged off.

Thank you.


How to restrict second user on Virtual Machine entry while first one is logged on


I find a method that the second user cannot "kick of" the first user.

Do you only want one user access the remote desktop at one time? If so, you can set the Group Policy to limit the number of the connections.

Open the Group Policy Editor, Locate to:
Computer Configuration\Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Connections

On the right pane, double-click Limite number of connections, click Enable, set the RD Maximus Connections allowed to 1.

In this way, the group policy restricts the second user to log on the remote desktop if someone is using the remote desktop.

Tuesday, May 30, 2017

Writing text in internet explorer while using element.sendKeys("abc") is very slow.


You can change to the 32-bit version, but in 64 bit IE is required then you can try this solution:

Internet Options -> Security -> Check "Enable Protected Mode" for all zone
Go to Advanced -> Security -> Check "Enable Enhanced Protected Mode"

=> No more snail typing on 64 bit IE (xD)

Thursday, March 16, 2017

What is test automation framework and it's basic framework types ?

A test automation framework is a combination of guidelines, coding standards, concepts, practices, processes, project hierarchies, reporting mechanism, test data, to support automation testing. A tester follows these guidelines while automating applications to take advantage of various productive results.

There are many types of test automation frameworks available in the market, and the most popular ones are listed here. Each one of these frameworks has their individual characteristics and features.
Let us now examine some of the popular frameworks and understand their pros, cons, and usability recommendations:

# Keyword-driven framework
In the keyword-driven framework, testers create various keywords and associate different actions or functions with each of these keywords. Function library contains the logic to read the keywords and call and perform the associated actions. Generally, test scenarios are written in excel sheets. The driver script reads the scenario and performs test execution. This is used in situations where the testers who create test scripts have less programming expertise, whereas framework creation is done by automation experts

# Hybrid framework
The hybrid automation framework is created by combining distinct features of two or more frameworks. This enhances the strengths of the different frameworks and mitigates their weaknesses. It is highly robust, flexible, and more maintainable. However, this requires strong technical expertise to design and maintain.

# Behavior-driven development framework
Behavior-driven development (BDD) framework automates validations in an easily readable and understandable format to business analysts, developers, testers, etc. Such frameworks do not
necessarily require the user to be acquainted with any programming language. There are different tools available for BDD like Cucumber, JBehave, and more which work along with other test automation tools. This framework is more suitable for applications using agile methodology and where user stories and early automation are required. It focuses on the behavior of the system rather than the implementation aspect of the system. The traceability between requirements and scripts is maintained throughout, and test scripts are easy to understand for the business users.

Sunday, November 6, 2016

What are the differences in between Download Speed, Upload Speed and Ping ?

The download speed is how fast you can pull data from the server to you. Most connections are designed to download much faster than they upload, since the majority of online activity, like loading web pages or streaming videos, consists of downloads. Download speed is measured in megabits per second (Mbps).

The upload speed is how fast you send data from you to others. Uploading is necessary for sending big files via email, or in using video-chat to talk to someone else online (since you have to send your video feed to them). Upload speed is measured in megabits per second (Mbps).

The ping is the reaction time of your connection–how fast you get a response after you've sent out a request. A fast ping means a more responsive connection, especially in applications where timing is everything (like video games). Ping is measured in milliseconds (ms).

Wednesday, September 23, 2015

Simple selenium with python example

'''
Created on Sep 22, 2015

@author: Prashant Chauhan

'''

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get('http://www.python.org')
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Python setup with selenium in eclipse

22092015

1. Install Eclipse any version.
2. Download and install JDK 7 or later
3. Download and install Python 2.7 or 3.5
4. Download the Selenium-2.47.3-py2-none-any.whl
5. Set the path for Java and Python Like :
    a. C:\python27\scripts
    b. %JAVA_HOME%/bin
6. Open command prompt and run :
    pip install -U selenium
7. Then you can see the result install selenium successfully the go further.
8. Install some more software in eclipse like:
    a. PyDev and PyDev Extension
    b. http://pydev.org/updates
    Then
    i: Trust the certificate.
    ii: Restart the eclipse
9: Now set the interpreter to the eclipse for creating projects.

10. Please run the simple program and enjoy.

Thanks:
Prashant Chauhan

Saturday, October 19, 2013

Smoke Vs Sanity Vs Regression Beautiful Example

We can consider a River Analogy to understand the difference between Smoke Testing, Sanity Testing and Regression Testing better. Before moving to the analogy, lets consider the very basic definition of three of these testing:
  • Smoke Testing: Testing all (wide) areas related to new feature, not deeply. Determines if we should go for further testing.
  • Sanity Testing: Testing narrow areas related to new feature, deeply.
  • Regression testing: Testing all areas related to new feature, deeply.
If we consider a river, for instance, which has, for instance 1000 feet width, and contains “dusts” in its water (which can be considered as “bugs” in software), the goal for the corresponding three types of tests should be as follows:



For Regression Testing: to find out all the dusts that are available on surface and under the water in all over the river.

"Testing all areas related to the new features deeply."


For Smoke Testing: to find out the dusts in all over the surface of the river, which not includes the dusts under water.

"Testing all (Wide) areas related to the new features, Not deeply. It determines if we should do further testing."


For Sanity Testing: to find out the dusts in a specific width (for instance left side 200 feet), which not only includes the dusts on surface, but also includes the dusts under water, till the last depth of the river.

"It is same as regression testing but here you make a risk judgement call and compromise part of your testing."


Thursday, August 1, 2013

Automate the Calendar component in Selenium WebDriver using JAVA.

package TestOpt;

import java.util.Calendar;
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;

interface Xpaths
{
/*
* This inteface contains all the xpath's that are used in the program
*/
String calendarPopUpButtonxPath = "//*[@id='j_id354:j_id355PopupButton']";
String monthIncrementerxPath = "//*[@id='j_id354:j_id355Header']/table/tbody/tr/td[4]/div";
String monthDecrementerxPath = "//*[@id='j_id354:j_id355Header']/table/tbody/tr/td[2]/div";
String dayxPathPart1 = "//*[@id='j_id354:j_id355DayCell";
String dayxPathPart2 = "']";
String dayZeroxPath = "//*[@id='j_id354:j_id355DayCell0']";
String applyButtonxPath = "//*[@id='j_id354:j_id355Footer']/table/tbody/tr/td[6]/div";
}

interface Months
{
int JANUARY   = 1,
FEBRUARY  = 2,
MARCH     = 3,
APRIL     = 4,
MAY       = 5,
JUNE      = 6,
JULY      = 7,
AUGUST    = 8,
SEPTEMBER = 9,
OCTOBER   = 10,
NOVEMBER  = 11,
DECEMBER  = 12;
int MAX_DAY_IN_A_MONTH = 31;
}

public class AutomateJsfCalendar implements Xpaths,Months
{
/**Months
* @param args
*/
static int targetDay     = 0,
          targetMonth   = 0,
          targetYear    = 0;
static int currentDay    = 0,
          currentMonth  = 0,
          currentYear   = 0;
static int jumpMonthsBy  = 0,
              index = 0;

static boolean increment = true;
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://livedemo.exadel.com/richfaces-demo/richfaces/calendar.jsf");
driver.manage().timeouts().implicitlyWait(15L, TimeUnit.SECONDS);
driver.manage().window().maximize();
WebElement element = driver.findElement(By.xpath(calendarPopUpButtonxPath));
element.click();
//At this point, jsf calendar component is displayed.
//Today's date is 30/03/2013. Let us say we want to set the date as 15/07/2013
String dateToSet = "15/07/2013";

GetTargetDateMonthAndYear(dateToSet);
GetCurrentDateMonthAndYear();
CalculateHowManyMonthsToJump();
for(int i=0;i<jumpMonthsBy;i++)
{
if(increment)
element = driver.findElement(By.xpath(monthIncrementerxPath));
else
element = driver.findElement(By.xpath(monthDecrementerxPath));
element.click();
try
{
//sleep will let you see the automation happening.
Thread.sleep(1000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
CalculateCorrectDayIndex(driver);
String completePath = dayxPathPart1 + index + dayxPathPart2;

element = driver.findElement(By.xpath(completePath));
element.click();
element = driver.findElement(By.xpath(applyButtonxPath));
element.click();

  //driver.quit();
}//end of main..
/*
*This method will bisect the target date and upadates  targetDay, targetMonth & targetYear variables.
*/
static void GetTargetDateMonthAndYear(String dateString)
{
int firstIndex = dateString.indexOf("/");
int lastIndex = dateString.lastIndexOf("/");
String month = dateString.substring(0, firstIndex);
targetDay = Integer.parseInt(month);
String day = dateString.substring(firstIndex+1, lastIndex);
targetMonth = Integer.parseInt(day);
String year = dateString.substring(lastIndex+1, dateString.length());
}
/*
* This method will fetch current date and updates currentDay, currentMonth & currentYear variables.
*/
static void GetCurrentDateMonthAndYear()
{
Calendar cal = Calendar.getInstance();
currentDay   = cal.get(Calendar.DAY_OF_MONTH);
currentMonth = cal.get(Calendar.MONTH)+1;//+1 because month values starts from 0. January = 0.
currentYear  = cal.get(Calendar.YEAR);
}
/*
* This method decides how many time this ">" element on the calendar component needs to be clicked to reach target month.
*/
static void CalculateHowManyMonthsToJump()
{
if((targetMonth - currentMonth) > 0 )
{
jumpMonthsBy = (targetMonth - currentMonth);
}
else
{
jumpMonthsBy = (currentMonth - targetMonth);
increment = false;
}
}

/*
* This calculates the current index that holds the targetDay value that we need to click in the calendar control.
*/
static void CalculateCorrectDayIndex(WebDriver driver)
{
int tempMonth = targetMonth - 1;
if(tempMonth == 0)
{
//if target month is January, control will come inside.
tempMonth = DECEMBER;
}
WebElement element = driver.findElement(By.xpath(dayZeroxPath));
String str = element.getText();
int dayValueAtZeroIndex = Integer.parseInt(str);

if(dayValueAtZeroIndex == 1)
{
index = targetDay - 1;
}
else
{
switch(tempMonth)
{
case JANUARY:
case MARCH:
case MAY:
case JULY:
case AUGUST:
case OCTOBER:
case DECEMBER:
{
index = ((MAX_DAY_IN_A_MONTH - dayValueAtZeroIndex) + targetDay);
break;
}
case FEBRUARY:
{
/*
* Separate case is needed for feb because Feb contains only 28(MAX_DAY_IN_A_MONTH - 3) days.
*/
index = (((MAX_DAY_IN_A_MONTH - 3) - dayValueAtZeroIndex) + targetDay);
break;
}
default:
{
//Control will come here for months that consists of 30(MAX_DAY_IN_A_MONTH - 1) days.
index = (((MAX_DAY_IN_A_MONTH - 1) - dayValueAtZeroIndex) + targetDay);
break;
}
}
}
}
}//end of class.

Selenium Solutions: Purpose: Selecting any date from JQuery Date Picke...

Selenium Solutions: Purpose: Selecting any date from JQuery Date Picke...: Purpose: Selecting any date from JQuery Date Picker using Selenium Web Driver Automating JQuery Date Picker is not as easy as selecting Da...

Wednesday, June 12, 2013

Selenium Web Driver Command List

Command;                                                       Description

driver.get("http://www.google.com"); To open an application
driver.findElement(By.id("passwd-id")); Finding Element using Id
driver.findElement(By.name("passwd")); Finding Element using Name
driver.findElement(By.xpath("//input[@id=’passwd-id’]")); Finding Element using Xpath
element.sendKeys("some text"); To type some data
element.clear(); clear the contents of a text field or text area
driver.findElement(By.xpath("//select")); Selecting the value
select.findElements(By.tagName("option")); Selecting the value
select.deselectAll(); This will deselect all Option's from the first SELECT on the page
select.selectByVisibleText("Edam"); select the OPTION with the displayed text of “Edam”
findElement(By.id("submit")).click(); To click on Any button/Link
driver.switchTo().window("windowName"); Moving from one window to another window
driver.switchTo().frame("frameName"); swing from frame to frame (or into iframes)
driver.switchTo().frame("frameName.0.child"); to access sub-frames by separating the path with a dot, and you can specify the frame by its index too.
driver.switchTo().alert(); Handling Alerts
driver.navigate().to("http://www.example.com"); To Navigate Particular URL
driver.navigate().forward(); To Navigate Forward
driver.navigate().back(); To Navigate Backward
driver.close() Closes the current window
driver.quit() Quits the driver and closes every associated window.
driver.switch_to_alert() Switches focus to an alert on the page.
driver.refresh() Refreshes the current page.
driver.implicitly_wait(30) Amount of time to wait
driver.set_script_timeout(30) The amount of time to wait
driver.get_screenshot_as_file('/Screenshots/foo.png') The full path you wish to save your screenshot to
driver.get_screenshot_as_base64() Gets the screenshot of the current window as a base64 encoded string which is useful in embedded images in HTML

Saturday, March 9, 2013

Difference between keyword driven and data driven framework ?

Data-Driven Testing
Simple test scripts have test data embedded into them. This leads to a problem that when test data needs to be updated actual script code must be changed. This might not be a big deal for the person who originally implemented the script but for a test engineer not having much programming experience the task is not so easy. If the script is long and non-structured the task is hard for everyone. Another problem with having the test data inside test scripts is that creating similar tests with slightly different test data always requires programming. The task may be easy original script can be copied and test data edited but at least some programming knowledge is still required. This kind of reuse is also problematic because one particular change in the tested system may require updating all scripts. Because of these problems embedding test data into scripts is clearly not a viable solution when building larger test automation frameworks. A better approach is reading the test data from external data sources and executing test based on it. This approach is called data-driven testing External test-data must be easily editable by test engineers without any programming skills. It is often in tabular format and edited in spreadsheet programs.

Keyword-Driven Testing
Previous section introduced data-driven testing and stated that it has multiple promises. It also mentioned that its biggest limitation is that all test cases are similar and creating totally new tests requires programming effort. A solution for this limitation, among others, is the keyword-driven approach where not only the test data but also directives telling what to do with the data are taken from test scripts and put into external input files. These directives are called keywords and test engineers can use them to construct test cases freely. The basic idea reading test data from external files and running tests based on it stays the same as in data-driven testing. keyword-driven testing is a logical extension to data-driven testing. 


Data Driven Framework :
It is nothing but data driven test, performing the same functionality with multiple input values by using parametrization with the help of data table or data source is called Data Driven Test.

Keyword Driven Framework :
It is nothing but keyword driven test or keyword view, used for parametrization.
It is dividing into 4 parts.
1. item     2. operation     3. value      4. documentation     ----> in QTP 8.2
In QTP 6.5 keyword view is nothing but Tree View. It displays the list of objects along with logical names.

Parametrization:
passing the run-time input values with the help of data-table or data-source is called parametrization.
Any queries

prashantlogic@gmail.com