Monday, September 17, 2018

Write response to a txt file groovy script on SoapUI


import net.sf.*; import net.sf.json.*; import net.sf.json.groovy.*; import net.sf.json.groovy.JsonSlurper; def Res = context.expand( '${GetAllSchoolsForAustralia#Response}' ) def slurper = new JsonSlurper() def json = slurper.parseText Res def countryList = json.result._source.city log.info countryList def file = new File('D:/XXX/CityListAU.txt'); file << countryList

Friday, September 7, 2018

Count child nodes of a JSON response using groovy in soapui



import net.sf.*;
import net.sf.json.*;
import net.sf.json.groovy.*;
import net.sf.json.groovy.JsonSlurper
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//Getting response from methods
def response = context.expand( '${Request 1#Response}' ).toString()

def slurper = new JsonSlurper()
def json = slurper.parseText response
def countryList = json.result.size()
def ActualResultNodeCount=countryList - 1
log.info ActualResultNodeCount


This is also very useful when accessing  test case data.
import java.net.*
def ts = context.testCase.getTestStepByName("RequestMaori-culture")
def endpoint =ts.getPropertyValue('Endpoint')
log.info endpoint

Wednesday, September 5, 2018

How to work with Windows image upload or file browser window on selenium with Jave

There are are several methods to handle this kinds of situation but not all are working ,Because most of them are to use with HTML file browser windows ,
This solution is specially for Windows file browser window AKA Windows file browser dialog box.

User first need to click on the file browser button,The there will be a Windows file browser dialog box where you can browse for a file.

In a nut shell what we are doing is just Copy and Past the file path at the Windows file browser dialog box

try {
    StringSelection s = new StringSelection("C:\\Users\\XXX\\Pictures\\w.png");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(s, null);
    Robot robot = new Robot();

    robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); //Press CTRL KEY
    robot.keyPress(java.awt.event.KeyEvent.VK_V);//Press V KEY
    robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); //RELEASE CTRL KEY
    Thread.sleep(3000);
    robot.keyPress(java.awt.event.KeyEvent.VK_ENTER);
} catch (AWTException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}

try {
    Thread.sleep(60000);
} catch (InterruptedException e) {
    e.printStackTrace();
}

Monday, September 3, 2018

java: cannot access java.util.function.Function class file for java.util.function.Function not found - Selenium on JAVA with InteliJ

I have below two lines on my selenium code.

WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(DashObj.HeaderText));

When i execute the test method as on the tittle im getting an error saying 
"java.util.function.Function class file for 
java.util.function.Function not found"

Fix:
Go to File ->Project Structure

There will be an window with some configurations.
Go to Modules and locate the Language level at Sources tab,


By default it was set to 7 , So click on the drop down and set it to 8.