Tuesday, May 12, 2020

Switch to another tab of same browser with Selenium WD using java

Test Scenario/step:

1. Open a browser say Firefox
2. Navigate to Test URL  https://link.testproject.io/bsg
3. Click Login link/button at top right corner --> It opens a new tab
4. Switch to new (2nd) tab and do whatever you need

Selenium Java code:

driver.get(" https://link.testproject.io/bsg");
driver.findElement(By.linkText("Login")).click();
//The following snippet of code is for switching to new tab
Set<String> handles = driver.getWindowHandles();
Iterator<String> it = handles.iterator();
while (it.hasNext()){
String child = it.next();
driver.switchTo().window(child);
}

Sunday, May 10, 2020

TestNG Assertion in Selenium WebDriver with Java

Test Scenario/Steps:

1. Open a browser (in my case Firefox)
2. Navigate to test URL say https://link.testproject.io/bsg
3. Assert the title of page
4. Click Login link at the top right corner
5. Enter invalid Username & Email --> Click Sign in button
6. Login will fail and a notification message will be displayed --> Assert the validation message

The following is the complete Selenium java code using TestNG framework:

package assertion_verification;

import java.util.ArrayList;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class ValidationOfInvalidLogin_TestNG {
private WebDriver driver;
JavascriptExecutor js;
String baseURL;
@BeforeClass
public void setUp() {
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\" + "src\\test\\resources\\Driver\\geckodriver-v0.24.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
js = (JavascriptExecutor) driver;
baseURL = "https://link.testproject.io/bsg";
}
@AfterClass
public void tearDown() {
driver.quit();
}

@Test
public void validationOfInvalidLogin() throws Exception{
//Open test URL: https://link.testproject.io/bsg
driver.get(baseURL);
Thread.sleep(3000);
//assertion of title of page using TestNG
String actualTitle = driver.getTitle();
String expectedTitle = "Free Test Automation For All – TestProject";
assertEquals(expectedTitle,actualTitle);
//OR,
assertTrue(actualTitle.contains(expectedTitle));

String parentWindowHandle = driver.getWindowHandle();
driver.findElement(By.linkText("Login")).click();
Thread.sleep(3000);

ArrayList<String> windowHandles = new ArrayList<String>(driver.getWindowHandles());
for (String window:windowHandles){
if (window != parentWindowHandle){
driver.switchTo().window(window);
}
}
Thread.sleep(3000);

driver.findElement(By.name("username")).clear();
driver.findElement(By.name("username")).sendKeys("fff@gmail.com");

driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("1234567890");
//Click Signin button
driver.findElement(By.id("tp-sign-in")).click();
//Assertion of notification message with TestNG
String actualMsg = driver.findElement(By.id("tp-message-error")).getText();
String expectedMsg = "Invalid username or password.";
assertEquals(expectedMsg,actualMsg);
}
}

Wednesday, May 6, 2020

Getting started with Selenium IDE

Selenium IDE is the starting for new to Selenium. It's a Chrome and Firefox extension.

Prerequisite: To install Selenium IDE in Firefox and Google Chrome.

Installation in FF:

1. Launch Firefox and navigate to https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/
2. Click on "+ Add to Firefox" link/button
3. Click Add button from permission prompt
4. Click "OK, Got it" from the dialogue at top right corner
5. Selenium icon will be displayed at the right side of address bar of browser after successful installation

Installation in Chrome:

1. Launch Google Chrome and navigate to https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd?hl=en
2. Click "Add to Chrome" link/button
3. Click "Add Extension" button from permission prompt
4. Selenium icon will be displayed at the right side of address bar of browser after successful installation

It's the time to get started--->
1. Open the browser say Firefox -> Click the Selenium icon at top right corner at address bar
2. Click "Create a new project" from Welcome dialogue of Selenium IDE
3. Enter Project name say "FirstTest" --> Click OK
4. Click Recording icon (REC) at the top right corner
5. Enter Test URL
6. Click START RECORDING button --> Your site will open to browse
7. Click some button/link, enter text in text box
8. Observe Selenium IDE --> It will record your test steps you did in step 7 having Command, Target and Value
9. Click Stop Recording icon (Red square inside red circle) at the top right corner and Save the project as .side extension say FirstTest.side
10. Replay the recorded test

Wednesday, March 4, 2020

Convert/Export Recorded Web, Android & iOS Tests to Java & C# with TestProject


Prerequisites:
1. Sign up: Open a browser  -> Visit TestProject and sign up
2. Activate your TestProject A/C: After signup go to your email and activate account by clicking 
    the link provided through your email
3. Login: Go to TestProject -> Click Login link at the top right corner and log in
4. Get TestProject Agent: Mouse over Agents menu item and download agent for your preferred
    OS (Windows, Linux, Mac)
5. Install, Launch and Register Agent: Install & launch Agent -> Register it
6. Record test: Record your desired tests by following the instructions from the link below:

The following is my recorded tests of Google search:

Now is the time to export your Recorded Tests to Code (Java or .NET C#) ...

Export recorded test to Java or .NET C#:

1. In order to export recorded tests to code, 1st step is to click the Three Dots at the right corner of
    your test and choose to “Generated Code” for the test you want to export as the screenshot as
    below:

2. The following option will be displayed:

3. Select Java or C# as programming language and select your preferred browser (such as Chrome,
    Edge, Firefox, IE, Safari) -> Click Generate button as shown in the screenshot above.
4. Save As option will be appeared for saving the exported code as below screenshot:

5. Now select your desired location -> Click Save button as above screenshot. Click OK from
    Generate code pop up.
6. Extract the zip file you saved (Say, Web_Test_2-My_Test_2-2020_03_02_12_25.zip).
7. Open the extracted code in your preferred IDE. Such as
    for Java you can use Eclipse, IntelliJIDEA.
    for .Net C# you can use Microsoft Visual Studio.


So, You can try TestProject for easier recording your tests as well as to convert your preferred programming language for making flexible & customizable.

Thursday, January 23, 2020

Automation Tools for Testing Desktop/Standalone Applications

List of some automated testing tools for Desktop/Standalone Applications

Free/Open source:

Winium
WinAppDriver
TestStack.White (White Framework)
Jubula
Pywinauto
Oracle Application Testing Suite
SikuliX
FlaUI
AutoIt
ZAPTEST
AirTest
Appium
LDTP (Linux Desktop Testing Project)
Robot Class / Win.form Class
TestArchitect
Tricentis Tosca
Micro Focus UFT (QTP)
Robot Framework
Conformiq

Commercial:

TestComplete
Ranorex

Monday, January 20, 2020

How to install Katalon Recorder on Windows

To install Katalon Recorder for Chrome

1. Open Chrome browser
2. Go to https://chrome.google.com/webstore/detail/katalon-recorder-selenium/ljdobmomdgdljniojadhoplhkpialdid
3. Click "Add to Chrome" button -> Click "Add extension"

To install Katalon Recorder for Firefox

1. Open Firefox browser
2. Go to https://addons.mozilla.org/en-US/firefox/addon/katalon-automation-record/
3. Click "Add to Firefox" button -> Click Add

How to install Genymotion on Windows 10

To install Genymotion on Windows 10

Prerequisites:
1. Go to https://www.genymotion.com/account/create/
2. Sign up and activate -> Sign in

Install Genymotion:
1. Download Genymotion for Windows (without VirtualBox) from
    https://www.genymotion.com/download/
2. Install after download the exe file (Default installation folder/target: C:\Program Files\Genymobile\Genymotion)