How can I run the same test case for different URLs?

Hi, I have several identical web pages hosted on different URLs. Can I create one test case and run it for these pages (in automatic mode)? If possible, the test case should be stored on the server and the scan must be performed on the server on a schedule. thank you in advance

I would show you how to run a Katalon Studio project for multiple URLs.

First, you create a GlobalVariable named ā€˜Hostnameā€™ in the Execution Profiles. The following screenshot shows the default profile having a GlobalVariable ā€œHostnameā€. Please note that I have a few more profiles named ā€œdevelopā€, ā€œproductā€ and ā€œstagingā€. These profiles stands for multiple environments I have for a single web app. Each of these profiles have ā€œHostnameā€ variables defined possibly with unique values.

On the other hand in your test case you will have WebUI.navigateToUrl() or WebUI.openBrowser() specifying URL with reference to the GlobalVariable.Hostname. Have a look at this screenshot.

In the Script view, I have this code:

import internal.GlobalVariable as GlobalVariable
...
WebUI.navigateToUrl("http://${GlobalVariable.Hostname}/")

Please note that ā€œimport internal.GlobalVariable as GlobalVariableā€ is necessary. And also the ā€˜GlobalVariable.ā€™ preceding to Hostname is necessary.

${ expression } in a String is a convenient syntax of Groovy language. See http://grails.asia/groovy-string-tutorial for further reading.

Finally you need to choose which Execution Profile to apply to an test case. On the top-right corner of Katalon Studio window, you would find a button labeled ā€œdefaultā€. By clicking it you would see a drop-down list where Profile names are listed. You want select one of them. Then the selected Execution Profile would be applied to the next execution of your test case. In other words, the value of ā€œGlobalVariable.Hostnameā€ defined in the selected Profile would be visible to your running test case.

Then all you need to do is to run your test case.

As you may be aware of, Katalon Studio has a feature ā€œConsole Mode Executionā€ https://docs.katalon.com/display/KD/Console+Mode+Execution. You can specify which Execution Profile to apply by the executionProfile switch.

-----

editted at 2018/07/17

I have made a running demo project and disclosed it on GitHub. The repository URL is
GitHub - kazurayam/KatalonDiscussion19067: demo for https://forum.katalon.com/discussion/comment/19067 How can I run the same test case for different URLs?

You can clone the project on your PC and try to run it. Also you can read the test case source code.

8i7wipjp1lxe.png

profiles_hostname.png

choose_which_profile_to_apply_to_a_test_case.png

The following Test Case is driven by data in an Excel Worksheetā€¦

Each row of the Excel Worksheet can be a new combination / permutation of URL, User Name and Password:
Column 1 is the URL for the login Page
Column 2 is the User Name
Column 3 is the Password

Then, all you have to determine is how many rows you need to enter in the Excel Worksheet in order to automatically test all of the combinations / permutationsā€¦

Test Case:
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.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

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.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.thoughtworks.selenium.webdriven.commands.RunScript as RunScript

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

import net.sourceforge.htmlunit.corejs.javascript.ast.ForLoop as ForLoop

import org.openqa.selenium.Keys as Keys

for (def row = 1; row <= findTestData(ā€˜Kuali Loginā€™).getRowNumbers(); row++) {

WebUI.openBrowser('')



WebUI.navigateToUrl(findTestData('Kuali Login').getValue(1, row))



WebUI.setText(findTestObject('Page_Kuali Login/Username'), findTestData('Kuali Login').getValue(2, row))



WebUI.setText(findTestObject('Page_Kuali Login/Password'), findTestData('Kuali Login').getValue(3, row))



WebUI.click(findTestObject('Page_Kuali Login/Sign In'))



WebUI.delay(5)  
  
//Call another Test Case that does what you would like to test in each URL  
WebUI.callTestCase(findTestCase('What you want to do next in your application'), \[:\], FailureHandling.STOP\_ON\_FAILURE)  



WebUI.closeBrowser()  

}

Victor,

If possible, the test case should be stored on the server and ā€¦

Do you mean you would install Katalon Studio and Chrome/Firefox browser into your Web App servers? I do not see why you want it.

kazurayam,we need to run the Katalon tests on linux and integrate the test cases and results with Jenkins CI

kazurayam said:

I would show you how to run a Katalon Studio project for multiple URLs.

First, you create a GlobalVariable named ā€˜Hostnameā€™ in the Execution Profiles. The following screenshot shows the default profile having a GlobalVariable ā€œHostnameā€. Please note that I have a few more profiles named ā€œdevelopā€, ā€œproductā€ and ā€œstagingā€. These profiles stands for multiple environments I have for a single web app. Each of these profiles have ā€œHostnameā€ variables defined possibly with unique values.

On the other hand in your test case you will have WebUI.navigateToUrl() or WebUI.openBrowser() specifying URL with reference to the GlobalVariable.Hostname. Have a look at this screenshot.

In the Script view, I have this code:

import internal.GlobalVariable as GlobalVariable

ā€¦
WebUI.navigateToUrl(ā€œhttp://${GlobalVariable.Hostname}/ā€)


Please note that "import internal.GlobalVariable as GlobalVariable" is necessary. And also the 'GlobalVariable.' preceding to Hostname is necessary.   
  
${ expression } in a String is a convenient syntax of Groovy language. See [http://grails.asia/groovy-string-tutorial](http://grails.asia/groovy-string-tutorial) for further reading.  
  
Finally you need to choose which Execution Profile to apply to an test case. On the top-right corner of Katalon Studio window, you would find a button labeled "default". By clicking it you would see a drop-down list where Profile names are listed. You want select one of them. Then the selected Execution Profile would be applied to the next execution of your test case. In other words, the value of "GlobalVariable.Hostname" defined in the selected Profile would be visible to your running test case.  
![](https://s3.amazonaws.com/katalon-forum/editor/e3/qnujlo601hen.png "Image: https://s3.amazonaws.com/katalon-forum/editor/e3/qnujlo601hen.png")  
  
Then all you need to do is to run your test case.  
  
As you may be aware of, Katalon Studio has a feature "Console Mode Execution" https://docs.katalon.com/display/KD/Console+Mode+Execution. You can specify which Execution Profile to apply by the **executionProfile** switch.

  

This is a pretty good explanation of how to setup a profile to use multiple URLā€™s thank you, with a bit of reading and figuring out I think I have understood your ā€˜call test case common/loginā€™ to enable you to use a username and password to log in, as part of this explanation if you could add the details or a link to ā€¦ of calling multiple usernames and passwords an how you set up those test cases? Iā€™m sure other new users would be very grateful, as I am thanks again.

I have made a running demo project and disclosed it on GitHub. The repository URL is
https://github.com/kazurayam/KatalonDiscussion19067

1 Like

kazurayam said:

I have made a running demo project and disclosed it on GitHub. The repository URL is
https://github.com/kazurayam/KatalonDiscussion19067

Thanks Kaz, Iā€™m very much an ā€˜apprenticeā€™ and any and all information has been very helpful, I also found this video tutorial https://www.katalon.com/videos/create-environment-profile/ ā€¦ thanks again!