Click few buttons then read .ini file

read

#1

Hi all,

Sorry for this very “beginner” question; I’d like to see if, in principle, Katalon can help me in this particular project, before starting to learn more about it:

I have a box (like your broadband router) for which I have built an administrative web interface (LAMP+Bootstrap+Jquery)
After user is playing with all the buttons and fields I provide, the end result is one .ini configuration file that is written on that box.

I would like to automate the testing of this GUI like so: Katalon should select some options, write some values, then click the “save” button. Then, it should get the .ini file, parse it, look for certain parameters, get their values, compare them with an accepted value (or a list of them, a numeric range, …) and only if the result is as expected, test should be considered successful.

(I guess Katalon cannot read files via ssh/ftp so, to offer access to the resulting .ini I can probably expose it via http; even more, I could convert it on-the-fly to something more suitable for Katalon, if needed, like XML or JSON.)

Can this be done in Katalon? I know it can simulate browser interaction but can it also read files, parse them and compare the found values with what is given in the test case?

Thank you in advance for your answer.

L.


#2

Katalon uses Groovy. Groovy “is” Java. It can do all of that, and more.

Yes.


#3

http://ini4j.sourceforge.net/


#4

Yes, you can.

You should expose your data via https://

You should convert *.ini to JSON and respond JSON back to Katalon Studio.

Then, Katalon Studio’s Web API Testing feature will be the best help for you. For example, verifying a value of a property in the Response is as simple as this:


#5

Thank you all very much for your prompt reply and the good news!
I’ll start digging then :slight_smile:

Cheers,
L.


#6

Hi,

with this pyhton code
import configparser
parser = configparser.ConfigParser()
parser.read('sampleconfig.ini')
for sect in parser.sections():
   print('Section:', sect)
   for k,v in parser.items(sect):
      print(' {} = {}'.format(k,v))
   print()

ugh, not able to add Java code here, will get 403 error

ini file contents
[owner]
name=John Doe
organization=Acme Widgets Inc.
age=24
height=176

[database]
server=192.0.2.62
port=143
file=“payroll.dat”


#7

hi,
I tried this in windows 10 cygwin installed.
first I created in Jidea class where used bash commands
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Level;

public class BashRunner {

    private static final Logger log = Logger.getLogger(BashRunner.class.getName());

    public List<String> run(String command) {

        List<String> arr = new ArrayList<>();

        Runtime run = Runtime.getRuntime();

        try {
            String line= "";
            String[] env = new String[]{"PATH=C:/cygwin64/bin"};
            Process proc = run.exec(new String[] { "C:\\cygwin64\\bin\\bash.exe", "-c", command },env);
            proc.waitFor();
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    proc.getInputStream()));
            while (br.ready()) {
                line = br.readLine();
                System.out.println(line);
                arr.add(line);
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, "failed " + command + " ", e);
        }
        return arr;
    }

    public List<String> getIniFile(String command1, String command2) throws IOException {

        List<String> arr = new ArrayList<>();
        arr = run( command1+" "+command2);
        return arr;
    }
}
then I created artifact (.jar) file in Jidea
added it to the Katalon Drivers folder
and used it in Katalon Studio
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

import com.kms.katalon.core.util.KeywordUtil

import BashRunner

KeywordUtil log = new KeywordUtil()

String expectedValue = "height=176";

	List<String> arr = new ArrayList<>();
	String command1 = "less"
	String command2 = "/home/myinifile.ini"
	BashRunner bash = new BashRunner();
	arr= bash.getIniFile(command1, command2);
	String joinedString = Arrays.toString(arr);
	
	boolean ans = joinedString.contains(expectedValue);
	
	if (ans){
		System.out.println("The list contains expected value: "+ expectedValue);
		log.markPassed("The list contains expected value: "+ expectedValue)
	}
	else{
		System.out.println("The list does not contains expected value: "+expectedValue);
		log.markFailed("The list does not contains expected value: "+expectedValue)
	}

Results
2019-04-21 16:54:50.373 DEBUG testcase.cygwinSsh                       - 7: arr = bash.getIniFile(command1, command2)
; Last modified 1 January 2019 by John Doe
; Example of INI File for Java
; myinifile.ini
[owner]
name=John Doe
organization=Acme Widgets Inc.
age=24
height=176

[database]
server=192.0.2.62     
port=143
file="payroll.dat"
2019-04-21 16:54:50.816 DEBUG testcase.cygwinSsh                       - 8: joinedString = Arrays.toString(arr)
2019-04-21 16:54:51.395 DEBUG testcase.cygwinSsh                       - 9: ans = joinedString.contains(expectedValue)
2019-04-21 16:54:51.398 DEBUG testcase.cygwinSsh                       - 10: if (ans)
2019-04-21 16:54:51.398 DEBUG testcase.cygwinSsh                       - 1: out.println("The list contains expected value: " + expectedValue)
The list contains expected value: height=176

#8

Hi. I noticed @kazurayam addressed the inquiry, which is can this task be done in Katalon ?. So I’ll mark this as a solved issue. If further problems along the road appear then you can create a new thread so the community can focus on helping you with new problems.

Cheers !