Monday, August 24, 2020

SoapUI :

How to add properties :


1) Project --> Doubleclick on Project --> Properties bottom .

2) TestSuite--> Doubleclick on TestSuite--> Properties bottom .

3) Testcase--> Doubleclick on Testcase--> Properties bottom .


Onemore way to add properties to testcase -->AddStep --> Property .(Properties add # not required .${CountryCode#Val})



========== syntax pass property values to testcase =========


${#Project#CountryName1}

${#TestSuite#Name}

${#TestCase#CName}



Static : <web:sCountryISOCode>IN</web:sCountryISOCode>


Dynamic : <web:sCountryISOCode>${#TestCase#CName}</web:sCountryISOCode> 


=============


Logs :

====

1)Project ---TestSuite --- TestSuite logs

2) TestcaseLevel---Doubleclick Testcase u can find.


Total soap ui logs we can find where soapui is installed --bin --> soapui.logs and soapui.errorlogs.

=============


Get and Set :

===========

we can get and set properties by Groovy scripty .


Diff between add and set property:

=================================

Add property add only Property not allow to asign any value.


Set Property we can add both .


=============  Property Transfer   ============



Note : if we want to pass 1 response out as a input to use Property Transfer.


1) Add a TestCase to Project name it as Property Transfer demo

2) Go to Soap resest of--CountryIScode -->clone Testcase --> Target Testcase as Property Transfer demo.

3) Go to Soap resest of--CapitalCity -->clone Testcase --> Target Testcase as Property Transfer demo.

4) Right Click on Testcase --> AddStep ..>Property Transfer.

5)Click Add button in Property Transfer.  


ref : https://www.youtube.com/watch?v=GSAt7YOvjbY&list=PLhW3qG5bs-L-Bt9T_bnyflQ0Te4VgFhKF&index=7



=====================



1. What is Script Assertion

2. How to add Script Assertion

3. Different assertion scripts for xml and json messages

4. Tips and Tricks

  


Script assertion works on the last reponse received in soapui

works with messageExchange object

(messageExchange object stores all the details of the last request and response)



Script Assertion samples

=====================


//check response time

assert messageExchange.timeTaken  4000


//check for Endpoint

 log.info messageExchange.getEndpoint() 


//check for TimeTaken

 log.info messageExchange.getTimeTaken()  


//check for header

log.info (messageExchange.responseHeaders["Content-Length"])

assert messageExchange.responseHeaders["Content-Length"] != null


//check attachments

assert messageExchange.responseAttachments.length == 0

log.info (messageExchange.responseAttachments.length)


//validate response nodes

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

def requsetHolder = groovyUtils.getXmlHolder( messageExchange.requestContent )

def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )

def refNum = responseHolder.getNodeValue("//m:CountryCurrencyResult/m:sName")

assert responseHolder.getNodeValue("//m:CountryCurrencyResult/m:sName") == "Rupees"


//to get response

def resp = messageExchange.responseContentAsXml.toString()



For JSON response

-------------------------------


//get json response

import groovy.json.JsonSlurper

def responseMessage = messageExchange.response.responseContent

def json = new JsonSlurper().parseText(responseMessage)


//assert node values

log.info json.name

assert json.capital.toString() != null

assert json.name.toString() == "[Taiwan]"


testStepName = messageExchange.modelItem.testStep.name//to get the Test Step Name

log.info testStepName

xmlHold = messageExchange.responseContentAsXml.toString()  //to store the response as Xml string



============================================== Start Assertions Xpath Match ===========================================



//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName[1]/m:iId

1488


//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName[1]/m:sName

Aaron Cresswell


Count sNametags presence:

count(//m:sName) 

2328


Tag presence:

//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName/m:sName

true


Check sName match:

matches(//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName[1]/m:sName,"Aaron Cresswell")

true


Check Names should have only alphabets:

matches(//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName[1]/m:sName,'[A-Za-z]*')

true


Check ID's should have only digits:

matches(//m:AllPlayerNamesResponse/m:AllPlayerNamesResult/m:tPlayerName[1]/m:iId,'\d')

true 

Wednesday, July 29, 2020

Extract desired word from string using regex in c#



string s = "1234 hyy dsad sfsf foorer dfdfdsf dvdvds";

            Regex regex = new Regex(@"\d+");
            var data = regex.Match(s);


output :1234

Saturday, July 25, 2020

Difference : Object, Var and Dynamic type


  public int Add(int a, int b)
        {
            object i = 100;

            i = i + 200;  // not allow arithmetic operations


            var s = 100;

            s = s + 100; // No error compile type checking

            dynamic ss = 100;

            ss = ss + 200;
            Console.WriteLine(ss);

            ss = "Hi"; // No error runtime type checking

        }

Difference : for and foreach




For:
 for(int i=0; i<1000; i++){
}
The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false.
There is a need to specify the loop bounds (minimum or maximum).
 Following is a code example of a simple for loop that starts 0 till <= 5.
foreach :
          foreach (var item in collection)
            {
              //  slow compare to for loop .
            // not allow to item modifications 
            }
we look at foreach in detail. 
What looks like a simple loop on the outside is actually a complex data structure called an enumerator:
An enumerator is a data structure with a Current property, a MoveNext method, and a Reset method. The Current property holds the value of the current element, and every call to MoveNext advances the enumerator to the next item in the sequence.
Enumerators are great because they can handle any iterative data structure. In fact, they are so powerful that all of LINQ is built on top of enumerators.
But the disadvantage of enumerators is that they require calls to Current and MoveNext for every element in the sequence. All those method calls add up, especially in mission-critical code.


Friday, July 17, 2020

ChromeOptions :



  • start-maximized: Opens Chrome in maximize mode
  • incognito: Opens Chrome in incognito mode
  • headless: Opens Chrome in headless mode
  • disable-extensions: Disables existing extensions on Chrome browser
  • disable-popup-blocking: Disables pop-ups displayed on Chrome browser
  • make-default-browser: Makes Chrome default browser
  • version: Prints chrome browser version
  • disable-infobars: Prevents Chrome from displaying the notification 'Chrome is being controlled by automated software
ChromeOptions options = new ChromeOptions()
options.addArgument("start-maximized");
ChromeDriver driver = new ChromeDriver(options);
https://www.guru99.com/chrome-options-desiredcapabilities.html

Tuesday, July 14, 2020

Local Q's: Reverse a String without using any loop or inbuilt methods?



  1. String reverse(String s)
  2. {
  3. if(s.length() == 0)
  4. return "";
  5. return s.charAt(s.length() - 1) + reverse(s.substring(0,s.length()-1));
  6. }

Saturday, June 27, 2020

RestSharp :


AddCookie :


request.AddCookie("__ngDebug", "false");
request.AddCookie("Steam_Language", "english");
request.AddCookie("sessionid", "123");

AddHeader :

added to the request you have generated, using request.AddHeader.

request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Content-Type","application/json");

AddUrlSegment

Replace a token in the request, by using request.AddUrlSegment. This will replace the matching token in the request.

request.AddUrlSegment("token", "1234");
request.AddUrlSegment("username","user");
request.AddUrlSegment("password","pwd");


AddParameter :

a new parameter will add to the request.

req.AddParameter("userLogin", _username,ParameterType.GetOrPost);

 req.AddParameter("password",_password, ParameterType.GetOrPost);


AddBody : we can add body in following ways :

1 ) Anonymous Body :
request.AddBody(new { Id = 1, Name = "Hi", Val = "123" });

2 ) Type Class Body :


public class Registration { public int Id { get; set; } public String Name { get; set; } public string Val { get; set; } }


request.AddBody(new Registration() { Id = 1, Name = "Hi", Val = "100" });


3) AddJsonBody :



 var body = new
            {
                Id = 1,
                Name = "ABC",
                Val = "123",
            };

          
  request.AddJsonBody(body);  or
 request.AddParameter("application/json; charset=utf-8", body , ParameterType.RequestBody);
4) complex object:
var user = new User { apiusername = "aaaaaa", apipassword = "aaaaaa", student_code = "asdhrthsefgserg", username = "asda21", password = "Admin@1", firstname = "qweqwq", lastname = "assaca", email = "as1@asda.com" }; var json = JsonConvert.SerializeObject(user); //Serialize before sending var client = new RestClient( "http://url.net/"); var request = new RestRequest(string.Format("edupro/apis/addstd/{0}", json),Method.GET); IRestResponse response = client.Execute(request); var content = response.Content;

Execute<>(Generic)Method:

// Execute no need to deserialize



var response = client.Execute<Registration>(request); //Registration model class
Assert.That(response.Data.Val, Is.EqualTo("123"), "not correct");



Restsharp : Deserialization