Saturday, 25 May 2019

UFT: Using Class File in UFT Action

'###CLASS FILE

ExecuteGlobal "Dim Reporter"
Set Reporter = New HtmlReporter


Class HtmlReporter
 
Public Sub Class_Initialize(  )
   
    print "started"
   
    Systemutil.CloseProcessByName "iexplore.exe"
    Systemutil.Run "iexplore.exe"
End Sub
   
'When Object is Set to Nothing
public Sub Class_Terminate(  )
       
    Systemutil.CloseProcessByName "iexplore.exe"
   
    print "ended"
End Sub
   
End Class



'###ACTION


msgbox datatable.Value("Value")


'#DATATABLE
Value
1
2
3

Saturday, 11 May 2019

ADODB my SQL Connection with VbScript

Function test()

On Error Resume Next

Set obj = CreateObject("ADODB.Connection")
Set obj1 = CreateObject("ADODB.RecordSet")
Dim dbquery
dbquery = "INSERT INTO test (firstname,lastname) VALUES ('neha','deshmukh');"

obj.Open "Server=db4free.net;Data Source=mysql; Database=sumit1234; User=sumit1234; Password=sumit1234;"

MsgBox obj1.State & ""

MsgBox Err.Description
obj1.Open dbquery, obj

MsgBox Err.Description

obj.Close
obj1.Close
Set obj1 = Nothing
Set obj = Nothing


End Function

Thursday, 9 May 2019

JDBC: My Sql Insert Statement

package mysqlconnect;

import java.sql.*; 
class Insert{ 
public static void main(String args[]) throws SQLException, ClassNotFoundException{ 
   
Class.forName("com.mysql.jdbc.Driver"); 
Connection con=DriverManager.getConnection( 
"jdbc:mysql://db4fre.net/sumit1234","sumit1234","sumit1234"); 
//here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password 
Statement stmt=con.createStatement(); 
String begin = "INSERT INTO `test`(`firstname`, `lastname`) VALUES ";

for (int i = 2000; i < 3001; i++) {

begin = begin + "(" + i + "," + (i + 10) + ")" + ",";
}

begin = begin.replaceAll(",$", ";"); //As we want ; after last value
stmt.executeUpdate(begin); //INSERT DELTE UPDATE needs executeUpdate
   
con.close(); 



}

JDBC: Mysql Select Statement

package mysqlconnect;

import java.sql.*;
class TestConnection{
public static void main(String args[]){

try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://db4fr.net/sumit1234","sumit1234","sumit1234");

// here db4fre.net/sumit1234 is server/database name, sumit1234 username and sumit1234password

Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from test");
while(rs.next())

System.out.println(rs.getString(1)+"  "+rs.getString(2));  //BE CAREFUL HERE . DIFFERENT FIELDS HAVE DIFFERENT datatype
//System.out.println("reached inside while");

con.close();  //Closing Connection

}catch(Exception e){ System.out.println(e);}
}
}



'################OUTPUT##################################################

sumit  raut
1  11
2  12
3  13
4  14
5  15
6  16
7  17
8  18
9  19
1  11
2  12
3  13
4  14
5  15
6  16
7  17
8  18
9  19
2000  2010
2001  2011
2002  2012
2003  2013
2004  2014
2005  2015
2006  2016
2007  2017


Monday, 29 April 2019

TestWork : Paraller Testing with TestNG and ThreadLocal in Selenium Java

//Base Class

package com.testcases;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class BaseClass {
private WebDriver driver;
public Date d = new Date();
public SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public String BROWSER = "chrome";
static ThreadLocal<WebDriver> dr = new ThreadLocal<WebDriver>();

public void setdriver(WebDriver driver) {
dr.set(driver);
}

public WebDriver getdriver() {
return dr.get();
}

public void init() {
if (BROWSER.contains("chrome")) {
System.setProperty("webdriver.chrome.driver", "G:\\chromedriver (2).exe");
driver = new ChromeDriver();
setdriver(driver);
getdriver().manage().deleteAllCookies();
getdriver().manage().window().maximize();

}

}

public void quit() {
getdriver().quit();

}

}



//Test Class 1

package com.testcases;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class ClassOne extends BaseClass {
Date d = new Date();

@BeforeMethod
public void start() {
init();
// df.format(date)

}

@AfterMethod
public void end() {
quit();
}

@Test
public void methodone() throws Throwable {
System.out.println("method 1 " + df.format(d) + "Thread " + Thread.currentThread().getName());
getdriver().get("http://www.google.com");
getdriver().findElement(By.name("q")).sendKeys("method 1");
}

@Test
public void methodtwo() throws Throwable {
System.out.println("method 2 " + df.format(d) + "Thread " + Thread.currentThread().getName());
getdriver().get("http://www.google.com");
getdriver().findElement(By.name("q")).sendKeys("method 1");
Thread.sleep(3000);
}

}


//Class two

package com.testcases;

import java.util.Date;

import org.openqa.selenium.By;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class Classtwo extends BaseClass {

@BeforeMethod
public void start() {
init();
}

@AfterMethod
public void end() {
quit();
}

@Test
public void methodthree() throws Throwable {
System.out.println("method 3 " + df.format(d) + "Thread " + Thread.currentThread().getName());
getdriver().get("http://www.rediff.com");
// getdriver().findElement(By.name("q")).sendKeys("method 3");
}

@Test
public void methodfour() throws Throwable {
System.out.println("method 4 " + df.format(d) + "Thread " + Thread.currentThread().getName());
getdriver().get("http://www.wwe.com");
// getdriver().findElement(By.name("q")).sendKeys("method 4");
Thread.sleep(3000);
}

}

//testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes">
  <test thread-count="5" name="Test" parallel="classes">
    <classes>
      <class name="com.testcases.Classtwo"/>
      <class name="com.testcases.ClassOne"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Tuesday, 16 April 2019

Java SimpleDateFormat

package coreJava;

import java.text.SimpleDateFormat;
import java.util.Date;

public class dateDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub
//current date..current time./
Date d= new Date();

SimpleDateFormat sdf=new SimpleDateFormat("M/d/yyyy");
SimpleDateFormat sd=new SimpleDateFormat("M/d/yyyy hh:mm:ss");
System.out.println(sdf.format(d));
System.out.println(sd.format(d));
System.out.println(d.toString());




}

}

Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...