Showing posts with label Rest Api. Show all posts
Showing posts with label Rest Api. Show all posts

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: 
  

How to Start Jersey Api Framework






 1. How to Use 
Jersey Hibernate File

step 1: Open dilsecodie
step 2: Rest Api section goto jersey part 
step 3: copy hibernate code in hibernate.cfg.xml 
step 4: use for session factory connection from the database any database  like Mysql,SQL , oracle 
step 5: the table should be mapped in hibernate file as an entity class.



From Jersey Framework we can develop any restful API structure 
To start with Jersey project, add jersey dependencies to pom.xml file in any dynamic 
projects mainly jersey dependency depend on these dependencies you can add these in your project.  
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.19.4</version>
</dependency>
 <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-atom</artifactId>
    <version>1.19.4</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-fastinfoset</artifactId>
    <version>1.19.4</version>
</dependency>
 <dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.19.4</version>
</dependency>

Now can add some changes in web.xml file 

<servlet>
  <servlet-name>s1</servlet-name>
  <servlet-class>
 org.glassfish.jersey.servlet.ServletContainer</servlet-class>
  <init-param>
  
  <param-name>jersey.config.server.provider.packages</param-name>
  <param-value>resource</param-value>
  
  
  </init-param>
 <init-param>
    <param-name>jersey.config.server.provider.classnames</param-name>
    <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>

  <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  <servlet-name>s1</servlet-name>
  <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
  </welcome-file-list>


So when any request comes to action class it is 1st call servlet where the rest as URL,
then its search endpoint  for API where its map its end from scanning param value 
packages to get all URLs 

ServletContainer is a servlet class that loads all packages which have URLs endpoint.

To start with Jersey project, add jersey dependencies to pom.xml file in any dynamic 
projects mainly jersey dependency depend on these dependencies you can add these in your project.  
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.19.4</version>
</dependency>
 <dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-atom</artifactId>
    <version>1.19.4</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-fastinfoset</artifactId>
    <version>1.19.4</version>
</dependency>
 <dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.19.4</version>
</dependency>

Now can add some changes in the web.xml file 

<servlet>
  <servlet-name>s1</servlet-name>
  <servlet-class>
 org.glassfish.jersey.servlet.ServletContainer</servlet-class>
  <init-param>
  
  <param-name>jersey.config.server.provider.packages</param-name>
  <param-value>resource</param-value>
  
  
  </init-param>
 <init-param>
    <param-name>jersey.config.server.provider.classnames</param-name>
    <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>

  <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  <servlet-name>s1</servlet-name>
  <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
  </welcome-file-list>


So when any request comes to action class it is 1st call servlet where rest as URL ,
then its search endpoint  for API where its map its end from scanning param value 
packages to get all URLs 

ServletContainer is servlet class that loads all packages which have URLs endpoint 
  
These are the import packages required for the jersey action class

import javax.servlet.http.HttpServletRequest; - for request handler 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.apache.wink.json4j.OrderedJSONObject;
import org.hibernate.Session; - to start hibernate session 

@Path("/demoList") - its for end point for API .