Tuesday, December 7, 2021

How to install Cypress on windows machine -

1. Download and install node.js

2. Open the cmd and type npm --version to check the npm version and type npm init.

3. After the initialization, Go to your project folder and Type 'npm install cypress --save-dev'

4. Wait for the installation to complete.

5. Cypress will be installed in your project folder (Cypress has now been installed in your ./node_modules directory, with its binary executable accessible from ./node_modules/.bin.)

6. Delete the cypress file from ./node_modules/.bin

7. Verify the cypress by using npx cypress verify.

8. To open the cypress, type cypress open and wait for a few seconds, the cypress application will be opened.


Kindly adhere to the following instructions to utilize the most recent edition:

  1. Acquire and install node.js.
  2. Launch VS code.
  3. Establish a new project.
  4. Activate the terminal and execute the subsequent commands to install the required components:

  • npm init -y
  • npm install cypress
  • npm install -D typescript
  • npm run cypress:open


Thursday, November 18, 2021

 

How to Click a button or links from browser console window by Using JQuery


var y = 0;
while( y < 2 ) 
    $x("//a[@class='wsmc-topmenu__breadcrumb-link--home']")[y].click();
    y = y + 1;
}

Result: 
Two times, the link or button will be clicked.

Try this solution and result is awesome.

Monday, July 19, 2021

Get most recent folder and move the files from one computer to another computer using batch commands

@echo off
FOR /F "delims=" %%i IN ('dir /b /ad-h /t:c /o-d') DO (
    SET a=%%i
    GOTO :found
)
echo No subfolder found
:found
echo Most recent subfolder: %a%

mkdir "\\DEE\AT\Files\%a%"
XCOPY %a% \\DEE\AT\Files\%a% /s /h /Y
pause 

Wednesday, April 14, 2021

How to get text from parent element and exclude text from children (C# Selenium)

Example: Suppose you have the following DOM

<h2 class="title">Charger

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>


<h2 class="title">Mobile

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>


<h2 class="title">Cable

<div class="default"> 

<span>method</span> 

<span class="sr-only">Default</span>

</div> 

</h2>

Solution: You can use the below code to fetch the parent element texts (i.e. Charger, Mobile and Cable) IList list = Application.driver.FindElements(By.XPath("//h2")); string[] texts = new string[list.Count]; foreach (IWebElement element in list) { texts[i] = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].firstChild.textContent;", element); i++; } return texts;

Friday, December 25, 2020

How to get the number of objects created in JAVA

Program to get the number of objects created in JAVA

public class Main

{

    static int i=0;

    public Main()

    {

        i++;

    }

    public Main(String name)

    {

        i++;

    }

public static void main(String[] args)

{

    Main m=new Main();

    Main m1=new Main("Balaji");

    System.out.println(i);

}

}

Output:

2

Wednesday, February 14, 2018

How to click the 'Second' element out of '8' matching element using Selenium Webdriver (Two elements in a page with same ID's)

Option 1:

You can use XPath indexing.

Example:
driver.findElement(By.xpath("(//*[@id="notificationStatusSwitch"])[2]"));

Option 2:

You can use findElements(): Using the given “locating mechanism” find all the elements on the current page.It returns a list of web elements, Then access the second one found

Example:

List<WebElement> elementList = driver.findElements(By.xpath("//*[@id="notificationStatusSwitch"]"));

elementList.get(1).click;

Thursday, February 1, 2018

Generate Extent Reports (Java) in Selenium WebDriver

In this article, we see one of the most popular and widely used Selenium Reporting Tools (Extent Reports).
What is Extent Reports?
Extent Report is an HTML reporting library for Selenium WebDriver for Java.
Features of Extent Report:
  • Allow is to generate logs inside HTML.
  • Generate PIE Chart based on test case status.
  • Generate Step summary.
  • We can filter reports depends on status.
  • It provides execution history.
  • It fetches system details like OS, Java Version, and Memory and so on.
  • Allow us the attached screenshot in the report that is a most important feature.

Pre-requisites to Generate Extent Reports:
1.    Java should be installed (Link to Install and setup Java )
2.    TestNG should be installed
3.    Extent Report Jars (Version 2.41.2)
4.    extent-config.xml – It allows to configure HTML Report

Steps To Generate Extent Reports:
1.    First, Create a TestNG project in eclipse
2.    Now download extent library files from the following link (http://extentreports.com/) and add the downloaded library files to your project.

Please refer the below sample code:

package com.Tests;
import java.io.IOException;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.BaseFixture.BaseFixture;
import com.CommonMethods.WebUtils;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class HomePage extends BaseFixture
{            
              String Login_Button_Obj=null;String Enter_Username_Obj=null;String Enter_Password_Obj=null;String Click_Login_Obj=null;
              String Username_Data=null;String Password_Data=null;String Search_Box_Obj=null;String Search_Text_Data=null;
              String Click_POTUS_Obj=null;String Follow_Link_Obj=null;String Click_Follow_Obj=null;
             
              ExtentReports reports;
              ExtentTest logger;
             
              @BeforeSuite
              public void beforeSuite()
              {
                             reports=new ExtentReports("D:\\Interview\\balaji-interview-framework\\AdvanceTestRun.html",true);                                                    
                             reports.addSystemInfo("Application URL","https://twitter.com/");
                             reports.addSystemInfo("Environment", "Live Environment");
                             reports.addSystemInfo("Author","Balaji G");                   
              }
             
              @BeforeTest
              public void launchApplication() throws IOException
              {                                                                                                                                                                                         
                            Login_Button_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Login_Button");                                                         
                            Enter_Username_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Enter_Username");
                            Enter_Password_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Enter_Password");
                            Click_Login_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Click_Login");
                            Search_Box_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Search_Box");
                            Click_POTUS_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Click_POTUS");
                            Follow_Link_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Follow_Link");
                            Click_Follow_Obj=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/ObjectRepository/HomePage/HomePageObject.properties","Click_Follow");
                            
                            Username_Data=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/DataRepository/HomePage/HomePageData.properties","Username");
                            Password_Data=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/DataRepository/HomePage/HomePageData.properties","Password");
                            Search_Text_Data=WebUtils.readDataFromPropertiesFile("D:/Interview/balaji-interview-framework/src/test/resources/com/DataRepository/HomePage/HomePageData.properties","Search_Text");
              }
             
              @Test(priority=0)
              @Parameters({"browser"})
              public void verifyHomePage(String bro)
              {            
                             logger=reports.startTest("Verify Home Page - Twitter");
                             boolean isElementFound=WebUtils.IsElementDisplayed(getDriver(bro),Login_Button_Obj);
                  if(isElementFound)
                  {                                                        
                            System.out.println("Twitter Home page is loaded successfully");
                            logger.log(LogStatus.PASS, "Twitter Home Page is loaded Successfully");
                  }
                  else
                  {
                            System.out.println("Twitter Home page is not loaded successfully");
                            logger.log(LogStatus.FAIL, "Twitter Home Page is not loaded Successfully");
                  }
                  reports.endTest(logger);
               }
             
              @Test(priority=1)
              @Parameters({"browser"})
              public void loginwithValidCredentials(String bro) throws InterruptedException
              {            
                             logger=reports.startTest("Verify Login with Valid Credentials - Twitter");
                             boolean isElementFound=WebUtils.IsElementDisplayed(getDriver(bro),Enter_Username_Obj);                            
                  if(isElementFound)
                  {                                                        
                                WebUtils.ClickElementByXpath(getDriver(bro),Login_Button_Obj);
                           
                            WebUtils.ClearInputByXpath(getDriver(bro), Enter_Username_Obj);
                                           WebUtils.EnterInputByXpath(getDriver(bro), Enter_Username_Obj, Username_Data);
                                          
                                           WebUtils.ClearInputByXpath(getDriver(bro), Enter_Password_Obj);
                                           WebUtils.EnterInputByXpath(getDriver(bro), Enter_Password_Obj, Password_Data);
                                           Thread.sleep(2500);
                                          
                                           WebUtils.ClickElementByXpath(getDriver(bro),Click_Login_Obj);
                                           System.out.println("Login Successful - Twitter");
                                           Thread.sleep(2500);
                            logger.log(LogStatus.PASS, "Login Successful - Twitter");
                  }
                  else
                  {
                            System.out.println("Login button is not available");
                            logger.log(LogStatus.FAIL, "Login button is not available. So Unable to login - Twitter");
                  }
                  reports.endTest(logger);
               }
             
              @Test(priority=2)
              @Parameters({"browser"})
              public void followPOTUS(String bro) throws InterruptedException
              {            
                             String expectedText="Follow";
                             logger=reports.startTest("Verify whether POTUS is following or not - Twitter");
                             boolean isElementFound=WebUtils.IsElementDisplayed(getDriver(bro),Search_Box_Obj);                            
                  if(isElementFound)
                  {                                                                               
                            WebUtils.ClearInputByXpath(getDriver(bro), Search_Box_Obj);
                                           WebUtils.EnterInputByXpath(getDriver(bro), Search_Box_Obj, Search_Text_Data);
                                           Thread.sleep(2500);                                  
                                           WebUtils.ClickElementByXpath(getDriver(bro),Click_POTUS_Obj);
                                           Thread.sleep(5000);
                                           String text=WebUtils.GetElementText(getDriver(bro), Follow_Link_Obj);
                                           if(text.equals(expectedText))
                                           {
                                                         WebUtils.ClickElementByXpath(getDriver(bro),Click_Follow_Obj);
                                                          Thread.sleep(5000);
                                                          System.out.println("Successfully Started Following - POTUS(Twitter)");
                                           logger.log(LogStatus.PASS, "Successfully Started Following - POTUS(Twitter)");
                                           }
                                           else
                                           {
                                                          System.out.println("Already Logged-in is Following - POTUS(Twitter)");
                                           logger.log(LogStatus.PASS, "Already Logged-in User is Following - POTUS(Twitter)");                  
                                           }
                  }
                  else
                  {
                            System.out.println("Search Textbox is not available");
                            logger.log(LogStatus.FAIL, "Search Textbox is not available");
                  }
                  reports.endTest(logger);
               }
             
              @AfterMethod
              @Parameters({"browser"})
              public void closeApplication(String bro,ITestResult result) throws Exception
              {
                             if(result.getStatus()==ITestResult.FAILURE)
                             {
                                           String screenShot_Path=WebUtils.captureScreenshot(getDriver(bro), result.getName());
                                           String image=logger.addScreenCapture(screenShot_Path);                                                                
                                           logger.log(LogStatus.FAIL, "FailedScreenshot", image);
                             }            
              }
             
              @AfterTest
              @Parameters({"browser"})
              public void endReport(String bro)
              {
                             getDriver(bro).quit();                  
    }
             
              @AfterSuite
              public void afterSuite()
              {
                             reports.flush();
                             SendMailSSLWithAttachment.mailTrigger();
              }

}

Sample Report: