Automation: Selenium Script to record Automation Test and Execution Video


Here we go, Selenium Screen Recorder: How To Record Selenium Test Execution Video

Techsouljours.blogspot.com - a blog for QA
Video Recording using selenium script


By using  Monte Screen Recorder API we record of our test cases as video format.

Monte Screen Recorder API available as Maven Dependencies where we can add in our POM.xml file as dependency tag.

How to Implement in our project :

We have one Java File of Recording screen functionality written and have attached as java file name as 'MyScreenRecorder.java' file

This 'MyScreenRecorder.java' file is the base function and we can use the method as 'MyScreenRecorder.startRecording("yourtestcase_recording")' in our own test case file.

For Example : Your Java file has the navigation function and if you want to record some scenarios, then we can use the method as 'MyscreenRecorder.startRecording' to start record and 'MyScreenRecorder.stopRecording' to stop the record.

@Test
public void navigation() throws Exception{

MyScreenRecorder.startRecording("Navigation_recording");

/*
                       your code goes here
                */
               MyScreenRecorder.stopRecording();

}

That's simple, your test case got recorded and saved in separate folder.

Results:

Here I have attached the screen recorder java file and ran for navigation from google to contus and from amazon to flipkart.


MyScreenRecorder.java

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.monte.media.Format;
import org.monte.media.FormatKeys.MediaType;
import org.monte.media.Registry;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;

import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;

public class MyScreenRecorder extends ScreenRecorder {
public static ScreenRecorder screenRecorder;
public String name;

public MyScreenRecorder(GraphicsConfiguration cfg, Rectangle captureArea, Format fileFormat,Format screenFormat, Format mouseFormat, Format audioFormat, File movieFolder, String name) throws IOException, AWTException
{
super(cfg, captureArea, fileFormat, screenFormat, mouseFormat, audioFormat,movieFolder);
this.name = name;

}

@Override
protected File createMovieFile(Format fileFormat) throws IOException {

if (!movieFolder.exists()) {
movieFolder.mkdirs();
} else if (!movieFolder.isDirectory()) {
throw new IOException("\"" + movieFolder + "\" is not a directory.");
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
return new File(movieFolder,
name + "-" + dateFormat.format(new Date()) + "." + Registry.getInstance().getExtension(fileFormat));

}

public static void startRecording(String methodName) throws Exception {
File file = new File("./recordings/");

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = screenSize.width;
int height = screenSize.height;

Rectangle captureSize = new Rectangle(0, 0, width, height);

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice()
.getDefaultConfiguration();

screenRecorder = new MyScreenRecorder(gc, captureSize,

new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey,ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,CompressorNameKey,ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE, DepthKey, 24,FrameRateKey,Rational.valueOf(15), QualityKey, 1.0f, KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black", FrameRateKey, Rational.valueOf(30)),null, file, methodName);

screenRecorder.start();

}

public static void stopRecording() throws Exception {
screenRecorder.stop();
}

}


MyTestDemo

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class MyTestDemo {

WebDriver driver;

@BeforeMethod
public void setup(){
System.setProperty("webdriver.chrome.driver", "E:\\Automation- setup files\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
}

@Test
public void navigationTest() throws Exception{
MyScreenRecorder.startRecording("NavigationTest_from_google_to_contus_viceversa");

driver.get("http://www.google.com");
driver.navigate().to("http://www.contus.com");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();

MyScreenRecorder.stopRecording();
}

@Test
public void navigation_FeatureTest() throws Exception{
MyScreenRecorder.startRecording("NavigationTest_From_amazon_to_flipkart_viceversa");

driver.get("http://www.amazon.com");
driver.navigate().to("http://www.flipkart.com");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();
driver.navigate().back();
driver.navigate().forward();

MyScreenRecorder.stopRecording();
}


@AfterMethod
public void tearDown(){
driver.quit();
}

Test Execution got recorded and video got saved. 


Video Recording in selenium script1


                                         
Video Recording in selenium script2

Full Script from the scrap and want to import in your project. 

Here is the Github URL 

By using this feature we can create AVI/Mp4 recording video files for your test case execution, which can be shared to developers while logging the bugs.

Post author by Siddarth

How to get started Devops learning and approaches


For Devops Engineer in initial level here are the things in order for you (priority high to low), open source tools awareness and QA roles in devops process.

techsouljours.blogspot.com-Devops-qa-roles and tools


  • Be Ready with Centos/Ubuntu commonly used commands set. You never know when you need what with these commands.
  • Learn What is CI/CD and What tools are used in CI and tools used in CD (just tool names).
  • Learn what is Git and Basic commands. (Because Git is most commonly used version control tool for your application source code management ). Sign up in github.com Build software better, together and learn how to push your code into it.
  • Coming to most common CI tools : Jenkins is most preferred and open-source. Try to install it on your own. (YouTube is your best friend here).
  • Once you are ready with github and jenkins. Create a simple jenkins build by Integrating jenkins with github.
  • Docker is another high on demand Devops tool. It's container based technology. Understand this as deep as possible.
  • Learn Kubernetes.
  • Learn Ansible/Chef (configuration management tools). Try to learn these 2 tools. (atleast 1 is preferred)
  • Jfrog artifactory. (artifacts/binaries management tools)
  • At last Learn any one of cloud technologies like AWS or Azure (what are they and how they works - learning at least 1 technology is preferred with certification at the end).
AWS provides infrastructure as a service, where you can learn installing all the above tools installation using various AWS services.

Popular Devops tools

There are many tools in Devops. Depending on the projects requirement and standardization we have to pick the right tool.

  • Most commonly used tools for source code management (as a version control system). Github, Gitstash, bitbucket, AWS code commit. Among above all GitHub is popular. You need to have git knowledge to use any of above tools.
  • For Continuous Integration there are many tools in the market. Some of commonly used tools are Jenkins, Bamboo, Teamcity, Concourse, CodeBuild etc. Among all above tools Jenkins is popular and easy to learn CI tool.
  • Configuration management tools like Ansible, Chef, Puppet, Salt.

API Security Testing - How to prevent from Hacking and vulnerabilities


Web API Security testing with it's API Fuzzer that can do Information Gathering, analyze Security Headers, identify API specific vulnerabilities which ensures, that system and applications in an organization, are free from any loopholes that may cause a big loss


techsouljours.blogspot.com-an-qa-blog

Types of API and their Uses

  • REST and SOAP API use predominantly use HTTP as their protocol
  • Arguments are sent as part of the URL, as HTTP Header or in the request body
  • Message payload is predominantly JSON for REST and XML for SOAP

Why Hack an API ?
  • Provoke error messages or response that give us system details
                      - Database names
                      - File Paths
                      - Component versions
  • Find Security holes that give us access to system resources
  • Put the API in an unavailable or unstable state (DOS) 
Security Standards for Web API
  • SSL commonly used for transport-level encryption
  • Message level encryption and signatures :
    • SOAP/XML: WS-Security and related standards
    • REST:JSON Web Algorithms
  • Authentication
    • SOAP: WS-Security/SAML
    • REST: Oauth 1 + 2, OpenID Connect, SAML, custom
API Attack Surface Detection
  • We want to know as much as possible about an APIs endpoints, messages, parameters behaviour
  • The more we know - the better we can target our attack
  • Unfortunately though - an API has no ‘UI’ that can show is the attack surface

techsouljours.blogspot.com - a blog for QA article about api secuirty testing
-apis: {

    -{            

       path:”/pet/{petID}”,



-operations: [
                                         techsouljours.blogspot.com - a blog for QA article about api secuirty testing
-{
   method: “DELETE”,u
   summary: “Delete a pet”,
   notes: “ ”                   
   type: “void”,
   nickname: “deletepet”,

- authorizations: {

                               techsouljours.blogspot.com - a blog for QA article about api secuirty testing
- Oauth2: {
                -{
                    scope: “write:pets”,
                    description: “modify pets in your account”
                  }
          ]
},
techsouljours.blogspot.com - a blog for QA article about api secuirty testing
- Parameters: [
     - {
           name: “petID”,
           description: “Pet id to delete”,
           required: true,
           type:”string”,
           paranType: “path”,


techsouljours.blogspot.com - a blog for QA article about api secuirty testing

           allowMultiple:false
        }
},


Attack Surface Detection : API Metadata

  • api-docs.json
  • WSDL/XML Schema
  • Swagger, RAML, API-Blueprint, ioDocs, etc
  • Hypermedia (JSON-LD, Siren, etc)
  • Documentation / Developer Portals

What are some whatspp hacks?

We would not call it a hack but yeah there are some tricks and tips which i know, gonna share with all of you !!
## If needed you can use WhatsApp as a best image cropper tool ( as we all know WhatsApp use some compression to make large size image into smaller one, so you can do that).
## Self Note / offline diary : you can also use WhatsApp as offline dairy , simply make grouo of some friend's, remove all of them and it's Done ! Now you can save all your useful stuff , data in that group and read offline too everywhere when needed.
Useful information from whatsapp
Whatsapp Tricks



INSTEAD OF CREATING GROUP…
SIMPLY ADD YOUR NUMBER AS CONTACT AND “Whatsapp” YOUR USEFUL STUFF TO IT…
## Now you can Tag someone in group chat just use ‘@’ tag in start of his/her name and WhatsApp will show list of names
## Send anything over WhatsApp: let assume you have to send Quora.apk file , simply Rename it as Quora.apk.mp4 and send it to your friend ! Done !
## UNBLOCK YOURSELF WITHIN 5 minutes
If someone blocked you on Whatsapp and you want to unblock yourself


How do I prepare for Selenium automation testing interviews?

Important topics and interview preparation for automation test engineer. Here are the list of contents explained with all useful links and updates. 
Now if we assume you are ready to go and get with this career move.
Time is not a constraint, it purely depends on person’s ability to grasp

software automation engineer interview preparation
Selenium-automation-interview-preparation

  1. Firstly, you need to learn any programming and scripting language like JAVA, Python, Ruby,etc.
  2. Get familiar with basic concepts like OOPS concepts, various Data Types and Variables, Operators, Decision Making, Arrays, Loops, Classes and Objects, Class Constructors, String Classes, etc.
  3. Now coming to selenium webdriver part start with Set Up/Configure Selenium WebDriver
  4. Get acquainted with various WebDriver Commands

    Below are the topics which you need to be clear to be a Professional Selenium Tester;
  1. Core Java
  2. Selenium WebDriver
  3. HTML traversal & DOM concepts
  4. CSS Selectors & XPATH
  5. JavaScript for Selenium Webdriver
  6. TestNG concepts for test organization, prioritization & batch execution
  7. Github concepts for source code management
  8. Jenkins for CD/CI
  9. Basic understanding of different frameworks - keyword driven, data driven, hybrid, POM
  10. Basic understanding of the workings of their current framework - folder structure, object repositories, reusable functions, test data flow, reporting libraries etc.

Appium Installation full setup on Mac for real device iOS automation (GUI & Command line tools)

Here I have displayed the procedure for the complete installation of Appium in mac for real device iOS automation. I have given the steps for Command line tool installation and GUI installation of appium in mac.

Command Line Tool Installation of Appium in MAC

Step 1 : Install java JDK:


Step 2 : Install Android Studio:


Scroll till last and find the software as below: 

android-studio-ide-173.4819257-mac.dmg

Step 3 : Install Home brew

--> In Terminal install brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 4 : Install Node.js

--> install node.js:

download installer: https://nodejs.org/en/download/ and run

Step 5 : Install npm

--> In Terminal install npm:
brew update
brew install node
npm install -g npm

Step 6 : To setup Environment 

To open bash_profile in terminal, type the following command:
nano ~/.bash_profile

or

open -e .bash_profile
If bash profile not available, create a bash_profile by following command

  1. Start up Terminal
  2. Type "cd ~/" to go to your home folder
  3. Type "touch .bash_profile" to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit.
paste following:

export ANDROID_HOME=/Users/user/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH

export JAVA_HOME=$(/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk)
export PATH=${JAVA_HOME}/Contents/Home/bin:$PATH
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH

export PATH=$PATH:/opt/bin:$PATH
save (Ctrl+S) and exit

NOTE : As default Android studio and Java takes the above path, if you have changed the path then do change it here with correct version

Step 7. Install Appium

In Terminal install Appium command line:
npm install -g appium@1.6.0-beta1
npm install wd
Step 8. Install Carthage 

Now type the following command to get into WebDriverAgent and Install carthage:
cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

brew install carthage

npm i -g webpack
Step 9. Run Appium in command line

From above steps do 'cd' to get out of all subfolders and then type 'appium'

- cd
- appium

If everything works correct you should get the following line 

[Appium] Welcome to Appium v1.6.0-beta1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

GUI Installation of Appium in MAC


Follow the Same steps from command line tools from Step 1 to Step 6


Detox: Gray Box End to End Testing Framework for Mobile Apps

Appium 

We used Appium for 2 years in general and for 8 months with React Native, and found that we invested an unreasonable portion of our time writing tests and petting the system than actually writing features.

We found that End to End testing is really hard:

Tests are flaky, we got different results on different machines, frequent failures in CI, which the only solution for was addition of sleeps, which slowed the tests down.

Tests were already slow since Apple UIAutomation tool is limited to performing one action per second, and there’s a hack which removes this cap Instruments without delays (which is already unmaintained), so after each release of a new Xcode we would have to wait for patch before upgrading.

Detox Gray box, not black box
Detox does Gray box, not Black box,

black box
A Black Box Testing

to allows the test framework to monitor the app from the inside and actually synchronize with it.

Gray box essentially uses a piece of code that is planted in the app, it can help us see what’s going on inside.

Unlike Black box, Gray box runs in the same process, has access to memory, and can monitor the execution process. Being able to read internal memory gives it the ability to detect what’s happening inside the process: if there are network requests in flight, when the main thread is idle, other threads are idle, Animations have ended, the react native bridge is idle. It can execute on main thread, to make sure that when it performs actions nothing in the UI hierarchy changes in the meantime.

Uses EarlGrey and Espresso
The leading native gray box drivers are developed by Google — EarlGrey for iOS and Espresso for Android. These frameworks can synchronize with the application, making sure to only interact with the app when it’s idle.

The underlying synchronization mechanism used in these gray box frameworks works in the following way.

Instead of retrying an action/expectation on the UI, they will query internal resources every few milliseconds or listen to callbacks from them telling that they have now switched to idle mode. The test will not continue until all of them return yes and only then, when the app is idle, it will interact with the UI.

React Native support

Detox is built from the ground up for native mobile and has deep first-class support for React Native apps.

We found out that React Native pretty much reimplements iOS and Android, so apart from the basic synchronization support of EarlGrey and Espresso for native apps, we had to create special synchronization mechanisms for React Native as well.

Evaluating expectations on the device


Traditionally, test frameworks evaluate expectations in the test script running on the computer. Detox evaluates expectations natively directly in the tested app running on a simulator. This enables operations that were impossible before due to different scope or performance reasons.

Does not rely on WebDriver

Detox does not rely on WebDriver, since this is not the web. Detox communicates with its native driver (which extends EarlGrey and Espresso) using a JSON-based reflection mechanism, this allows a common JavaScript implementation to invoke native methods directly on the device.

How Detox Works