Tuesday, July 4, 2017

Create and Run Python Script in Linux Command Line

Create and Run Python Script in Linux Command Line


create python script in linux
  1.  cd scratch
  2. mkdir new_folder
  3. cd new_folder
  4. touch test.py
  5. vi test.py
  6. Press "i"  - this will open the file in edit mode
  7. Enter below lines :
    #! /usr/bin/python
    print('Hello, world!')
  8.  Press "esc"
  9. type ":wq!" without quotes
  10. chmod a+x test.py
  11. ./test.py

Friday, May 12, 2017

Java : CSV

how to work with CSV Files

use opencsv library file
( https://mvnrepository.com/artifact/com.opencsv/opencsv)

import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;

public class csv_file {
String sPath=".\\src\\test.csv";

public static void main(String[] args) throws IOException{
csv_file c=new csv_file();
ArrayList<String[]> data=new ArrayList<String[]>(); // Arraylist which stores string array type
String[] a_data={"hi","one"};
String[] a_data2={"this","is","50"};
data.add(a_data);
data.add(a_data2);
c.opencsv_writeAll(data);
System.out.println(c.opencsv_read());
}

public ArrayList<String[]> opencsv_readAll() throws IOException{
CSVReader csv = new CSVReader (new FileReader(sPath));
ArrayList<String[]> data=(ArrayList<String[]>) csv.readAll();
csv.close();
return data;
}
public ArrayList<String[]> opencsv_read() throws IOException{
CSVReader csv= new CSVReader (new FileReader(sPath));
ArrayList<String[]> data=new ArrayList<String[]>();

for(Iterator<String[]> i=csv.iterator();i.hasNext();)
data.add(i.next());
csv.close();
return data;
}

public void opencsv_writeAll(ArrayList<String[]> data) throws IOException{
CSVWriter csv= new CSVWriter (new FileWriter(sPath,true));
csv.writeAll(data);
csv.close();
}
public void opencsv_write(String[] data) throws IOException{
CSVWriter csv= new CSVWriter (new FileWriter(sPath,true));
csv.writeNext(data);
csv.close();
}

}

Java : Array List of Array ( ArrayList )


Array List of Array ( ArrayList<String[]> )


Example:

// Variable can be ArrayList<String[]> as well

List<String[]> AList= new ArrayList<String[]>();
String[] addressesArr = new String[3]; addressesArr[0] = "zero"; addressesArr[1] = "one"; addressesArr[2] = "two";

String[] addressesArr2 = {"hi", "there"};
AList.add(addressesArr);
AList.add(addressesArr2);

Monday, May 8, 2017

Java : (Swing) JTable

Java : (Swing) JTable

JTable : Used when more than 1 column is required

Pre -Req :

  1. Make sure Window Builder addon is installed into eclipse
  2. Create a New Swing Designer >app Window > Save
  3. In Design Mode > add a JList Component 
Method 1:
DefaultTableModel model = new DefaultTableModel();
model.addColumn("A");
model.addColumn("B");

table = new JTable(model);
frame.getContentPane().add(table, BorderLayout.CENTER);
model.addRow(new Object[]{"1", "Deeapk"});


Method 2:

String[] Cols={"A" , "B"};
Object[][] data={
{"1","deepak"},
{"2","Alex"},
};

table = new JTable(data,Cols);
frame.getContentPane().add(table, BorderLayout.CENTER);


Code with Scroll bar :
frame = new JFrame();
DefaultTableModel model = new DefaultTableModel();
table = new JTable(model);
scrollPane = new JScrollPane(table);
scrollBar = new JScrollBar();

frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);

scrollPane.add(scrollBar);

model.addColumn("A");
model.addColumn("B");

for(int i=1;i<50;i++){
model.addRow(new Object[]{i, "Deeapk"});
}


 

Java : ( Swing ) Jlist

(Swing) JList

JTable : Used when only 1 column is required

Pre -Req :
  1. Make sure Window Builder addon is installed into eclipse
  2. Create a New Swing Designer >app Window > Save
  3. In Design Mode > add a JList Component


DefaultListModel<String> listModel = new DefaultListModel<>();
            listModel.addElement("USA");
            listModel.addElement("India");
            listModel.addElement("Vietnam");


JList list = new JList(listModel);
 frame.getContentPane().add(list, "cell 0 1 7 4,grow");


Wednesday, April 26, 2017

Java : Accept Input Java

Java : Accept Input Java



 String test1= JOptionPane.showInputDialog("Please input mark for test 1: ");

Thursday, March 9, 2017

SOAPUI : Access Properties at different levels (Property Expansion)

Access Properties at different levels (Property Expansion)


Property Expansion(http://readyapi.smartbear.com/features/expansions/syntax) :

1) TestStep properties =  ${TestStepName#MyPropertyName}
2)Test case properties =${#TestCase#MyPropertyName}   -- Here TestCase is keyword
3)Project properties =   ${#Project#MyPropertyName}  --- Here Project  is keyword

Examples:
log.info context.expand('${#TestCase#endpoint3}')   // Groovy
or
Directly use : ${#TestCase#endpoint3}
In any Request


Using Properties values from a different testcase :


-----Working with current test case -----------
SET    :     testRunner.testCase.setPropertyValue("endpoint",endpoint)
GET :       log.info testRunner.testCase.getPropertyValue("endpoint")


----------------------------Working with some other test case -------------
get Value :
def project = testRunner.testCase.testSuite.project
log.info project.testSuites['TestSuite 1'].testCases['TC anme'].getTestStepByName("StepName").getPropertyValue("property_name")

Example :
def project = testRunner.testCase.testSuite.project
log.info project.testSuites['TestSuite 1'].testCases['GenericKmauthtoken'].getTestStepByName("Count").getPropertyValue("authentication_PropertyFile")

Wednesday, March 8, 2017

SOAPUI : Extract xml response

Extract xml response


def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
responseContent = testRunner.testCase.getTestStepByName("TestStepname").getPropertyValue("response")
//"response" is keyword

def holder = groovyUtils.getXmlHolder(responseContent)
log.info holder.getNodeValue("//locale/recordId")  // Here "locale/recordId" is like  //Parentnode/node

SOAP UI : Call Another Test Case using Groovy script

Call Another Test Case using Groovy script


RUN TEST CASE

def project = testRunner.testCase.testSuite.project
def runner = project.testSuites['Suite_name'].testCases['testCase_name'].run( null, true )
runner.waitUntilFinished()

example :
def project = testRunner.testCase.testSuite.project
def runner = project.testSuites['TestSuite 1'].testCases['GenericKmauthtoken'].run( null, true )
runner.waitUntilFinished()

RUN TESTSTEP

def project = testRunner.testCase.testSuite.project
testRunner.runTestStep( project.testSuites['TestSuite1'].testCases['TestCase2'].testSteps['GroovyScript'] )

example:
def project = testRunner.testCase.testSuite.project
testRunner.runTestStep( project.testSuites['TestSuite 1'].testCases['GenericKmauthtoken'].testSteps['initialization'] )





Ref : 
https://community.smartbear.com/t5/SoapUI-NG/Res-Calling-test-cases-and-test-steps/td-p/18186/page/2

Monday, January 30, 2017

Best Editor for working with Log files and Regex support

Best Editor for working with Log files and Regex support 


Best Editor for working with Log files -Editpad Lite or Pro
Download https://www.editpadlite.com/

Online Regex Testing site :
http://regexr.com/
http://www.regexe.com/
http://myregexp.com/

RegEx Cheat sheet
https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/

Common Examples:

* Ah* matches "Ahhhhh" or "A"

? Ah? matches "Al" or "Ah"

+ Ah+ matches "Ah" or "Ahhh" but not "A"

\ Hungry\? matches "Hungry?"

. do.* matches "dog", "door", "dot", etc.

( ) See example for |

[ ] [cbf]ar matches "car", "bar", or "far"
[0-9]+ matches any positive integer
[a-zA-Z] matches ascii letters a-z (uppercase and lower case)
[^0-9] matches any character not 0-9.

| (Mon)|(Tues)day matches "Monday" or "Tuesday"

{ } [0-9]{3} matches "315" but not "31"
[0-9]{2,4} matches "12", "123", and "1234"
[0-9]{2,} matches "1234567..."

^ ^http matches strings that begin with http, such as a url.
[^0-9] matches any character not 0-9.

$ ing$ matches "exciting" but not "ingenious"

Monday, January 9, 2017

SOAP UI: Dynamically Change the Reponse/method in the Test Step

Dynamically Change the Response/Method in the Test Step

To Dynamically change the  response / method in the Test step , user needs to replace the URL in the scratch pad itself with the variables .

In the below example , I'm grabbing the id value from properties file(counter) in the response.For that I have first modified the scratch pad Resource ,this gets reflected in the test step and can be used further.