Saturday, January 22, 2022

How to make testing cases using Selenium scripts






Step1: open dilsecodie
Click on the login button present in my account of yourwebsite.com
Check you are able to do testing on the login button to get scripts from the selenium section.

Testing Importance 
Testing importance for project bug fixing or related issues.
Automation testing done by selenium scripts.
Selenium can also check code standards, which also helps in audit security points.

Some Test scripts we can use.
Demonstration on a few parameters of @Test annotation as shown below. <br>

package demo test; 

import org.testing.Reporter;

import org.testng.annotations.Test; 

public class DemoA { 
--- its 1st case for testing priority wise 
@Test(priority=1, groups={"user", "smoke"}) 

public void CreateUser(){ 

Reporter.log("CreateUser", true); 

--- its 2nd case for testing priority wise enabled as true 
@Test(priority=2, invocationCount=1, enabled=true, groups={"user"}) 

public void editUser(){

Reporter.log("editUser", true); 


@Test(priority=3, groups={"user"}) 

public void deleteUser(){ 

Reporter.log("deleteUser", true); 

}

@Test(priority=1, groups={"product", "smoke"}) 

public void createProduct(){ 

Reporter.log("createProduct", true);


@Test(priority=2, invocationCount=1, enabled=true, groups={"product"}) 

public void editProduct(){ 

Reporter.log("editProduct", true); 


@Test(priority=3, groups={"product"}) 

public void deleteProduct(){ 

Reporter.log("deleteProduct", true); 

} }

This program demonstrates Upcasting concept (FirefoxDriver class object to WebDriver interface) and accessing various methods of the WebDriver interface

package qspiders; 

import org.openqa.selenium.WebDriver; 

import org.openqa.selenium.firefox.FirefoxDriver;

public class UpcastingToWebDriver_LaunchBrowser { 

 
Parameterisation using @DataProviders

1. DataProvider is an annotation in testng using which we can create data bank.

2. THis databank can used across any testng class , thus achieiving data parameterisation.

Executing the same script with multiple sets of data is called data parameterisation.

From Testng Class by creating our own data bank using DataProvider annotation

From Testng class

1. We use DataProvider annotation to create the data bank,

2. We utilise this data from any testng methods by using

"dataProvider" parameter as an argument to "Test" annotation.

code :

package scripts;

import org.testing.Reporter;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Test;

public class DataProviderExample{

@DataProvider

public Object[][] dataBank(){

Object[][] data = new Object[2][2];

data[0][0] = "admin1";

For another web element:


What is a WebElement? 

1. Any element present on a web page is called a web element. 

2. Developers use HTLM code to develop web pages. 

3. For testing purposes, we can also create a web page using HTML code. 

4. In order to create a web page, we need to write HTML code in any text pad (eg : notepad and save the file with .html extension) 

Create a sample web page using HTML as mentioned below. 
<html> 
<body> 
UN : <input type="text" id = "username" value = "admin"> 

PWD: <input type="text" id= "pass" value = "manager"> 

< a href="http://dilsecodie:8080/login.do"> Click Link</a> 

In the above HTML tree, every element should have one of the 3 options. 

1. Tagname (this is mandatory for all the elements) 
2. Attributes (Optional) 
3. Text (Optional) 
Example of Tagname in the above HTML Tree structure: 

 HTML, 
 body, 
input, 
 a 
Example of Attributes in the above HTML Tree structure: 

 type = "text" 

 id = “username” 

value = "admin" 

Format : attributeName = "attributeValue"

Example of Text in the above HTML Tree structure: 
  

No comments:

Post a Comment