Open link from CVS File

Hello Everyone.

I have a CSV file with various links. I want these links to be read from the CSV file and opened in the browser to perform certain steps. After that the next link should be opened and so on.

Thank for your help!

Check out the guide on using CSV files here Data-driven testing in Katalon Recorder | Katalon Docs and then check out How to implement data-driven testing in a test case with Katalon Recorder | Katalon Docs

hi,
regex all links to the list and then loop the list as datadriven doc shows

here is something how to do it

one example how to do it

csv file contents
csv_example.csv
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list
This is http://stackoverflow.com/questions; and https://stackoverflow.com/questions/24104313/how-do-i-make-a-delay-in-java; The code below catches all urls in text and returns urls in list

TestCase

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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
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.testng.keyword.TestNGBuiltinKeywords as TestNGKW
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 com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys


String csvPath = "C:\\Users\\xxxxxx\\Desktop\\csv_example.csv";

ArrayList<String> list0 = CustomKeywords.'com.csv.ReadCsvFile.readLinksFrom'(csvPath) 
String csvString = list0.toString();


ArrayList<String> list = CustomKeywords.'com.csv.ReadCsvFile.splitUrl'(csvString) 
for (String s : list) {

	WebUI.openBrowser('')
	
	s = s.replace(";","");
	System.out.println(s);
	//do what you want to do here with links
	WebUI.navigateToUrl(s)
	
	WebUI.delay(1)
	
	WebUI.closeBrowser()
}

Keyword
package com.csv

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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.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
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows

import internal.GlobalVariable

import com.opencsv.CSVReader;
import java.io.FileReader;
import java.util.ArrayList;

public class ReadCsvFile {
	

	@Keyword
	public ArrayList<String> splitUrl(String s) {
		ArrayList<String> list = new ArrayList<>();
		int spaceIndex = 0;
		while (true) {
			int httpIndex = s.indexOf("http", spaceIndex);
			if (httpIndex < 0) {
				break;
			}

			spaceIndex = s.indexOf(" ", httpIndex);
			if (spaceIndex < 0) {
				list.add(s.substring(httpIndex));
				break;
			} else {
				list.add(s.substring(httpIndex, spaceIndex));
			}
		}
		return list;
	}


	@Keyword
	public ArrayList<String> readLinksFrom(String path){

		ArrayList<String> list = new ArrayList<>();

		CSVReader reader = null;
		try
		{
			//parsing a CSV file into CSVReader class constructor
			reader = new CSVReader(new FileReader(path));
			String [] nextLine;
			//reads one line at a time
			while ((nextLine = reader.readNext()) != null)
			{
				for(String token : nextLine)
				{
					System.out.print(token);
					list.add(token);
				}
				System.out.print("\n");
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return list;
	}
}

Probably I have misunderstood or such a function is not provided Katalon Recorder.
This is the structure of the table:
Id: Link:
5501 http://www.xfjhkh.com/adfoe/kkjkjiuh?&5501
5502 http://www.xfjhkh.com/adfoe/kkjkjiuh?&5502

5724 http://www.xfjhkh.com/adfoe/kkjkjiuh?&5724

So Katalon Recordre should copy from column Link or B2 the link or also copy it as text and enter it in the address line of a browser and open the page. Here follow some test steps and the page is closed. Then the next link is read out and so on.
Possibly this function does not exist at all.

Did you find out the solution?

Hi nas

If you read the links I’ve already shared with you then you will find that Katalon Recorder does support what you’re trying to do.

The ‘open’ command supports opening links in the browser, and if you combine it with the data driven testing instructions, this will then open up those links for you.

Hello Noor Ahmed Khan

no not yet. But I am checking guy.masons’ instruction links again.

thanks

Adem Akyüz

ping me on skype
I will try to help you out

noor.ahmed@skylines.ae

Hello Timo Kuisma1,

thank you alot.

So mostly such solution suggestions take a lot of work off my hands. But I don’t really understand this approach, which is why I find it difficult. I don’t understand it because I’m not a programmer and the listing of links confuses me.

But maybe I can figure it out.

Thanks a lot anyway!

Adem Akyüz

Hello,

solved. Thank you for your help!

Adem Akyüz

i rejoiced too soon. The link is read from the CSV file, but the link does not open in the browser. To test this I just have the command Loadvars and open with ${Links} as value. Unfortunately without success.

If you look at the ‘Variables’ tab within Katalon Recorder, you can see what values are being stored against what variables.

If the variable for the link isn’t populated (e.g. if it’s empty), then the open command won’t work either.