Selenium code migration to Katalon Studio...Unable to run the code

Hi there,

I followed below steps for migration of a piece selenium TestNG code to Katalon studio. Am getting error while running the TC. Please help me understand what I am missing here
pre-requisite: Added Selenium/TestNG plugin

  1. Copied selenium code under Include /Scripts/groovy/package/test.java and pageobject under same package
  2. Imported all the related libraries manually under Project/settings/External libraries since not aware of format to add maven libraries into build.gradle
  3. Created a TC and added TestNG Keyword to call the java class as follows
    List testClasses =[‘test.class’]

TestNGKW.runTestNGTestClasses(testClasses)

Getting below error while running the TC
Test Cases/IdentifiAppl/SeleniumLoginScript FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Keyword runTestNGTestClasses was failed (Root cause: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘test.class’ with class ‘java.lang.String’ to class ‘java.lang.Class’ due to: java.lang.ClassNotFoundException: test.class

Appreciate a quick and detailed response!

Regards,
Sneha

You might get a detailed response (though nobody can promise you “quick”) if you post more detail in your question.

Please follow this advice - make sure your error includes any “Caused by” line:

re-writing the question again
pre-requisite : Have added Selenium/TestNG plugin

  1. Copied selenium code under Include /Scripts/groovy/package/IdentifiLogin.java and pageobject under same package

  2. Imported all the related libraries manually under Project/settings/External libraries since not aware of format to add maven libraries into build.gradle


  3. Created a TC and added TestNG Keyword to call the java class as follows

image

List testClasses =[‘IdentifiLogin.class’]
TestNGKW.runTestNGTestClasses(testClasses)

Getting below error while running the TC
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘IdentifiLogin.class’ with class ‘java.lang.String’ to class ‘java.lang.Class’ due to: java.lang.ClassNotFoundException: IdentifiLogin.class

@Sdhongadi
Please change script to:

List testClasses = [IdentifiLogin.class]
TestNGKW.runTestNGTestClasses(testClasses)

the list testClasses should be a list of class, not list of string as class name.

1 Like

Re-ran the TC, getting below error

=============== ROOT CAUSE =====================

================================================

07-28-2020 08:32:51 PM Test Cases/IdentifiAppl/SeleniumLoginScript

Elapsed time: 2.877s

Test Cases/IdentifiAppl/SeleniumLoginScript FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: IdentifiLogin for class: Script1595830441555
at SeleniumLoginScript.run(SeleniumLoginScript:19)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)

@Sdhongadi

You are missing import statement in test case script:

import identifi

or press Ctrl + Shift + O

Thank you so much… am able to run my script
It was a great help :slight_smile:

Also curious to know instead of manually adding all the external libraries , can i just copy my maven dependencies into build.gradle. will that work?

The following post tells you how to copy your external dependencies (jar files) into the Drivers directory driven by Gradle’s dependency management.

Hi
Followed above steps and tried to add one dependency using above method.

  1. Added below dependency in build.gradle
    image

  2. Navigated o project path and executed the command given but giving below error

Do not type “$ gradle …”.

Just type “gradle …”

yes tried!

I see message:

'gradle' is not recognized as an internal or external command,
operable program or batch file.

Did it work?

If not, do you have gradle command installed?

If not yet, see https://gradle.org/install/

@Sdhongadi

If you want to use gradle to manage external libraries, you should install gradle binary first like @kazurayam said.
However, if you use selenium-java:3.141.59 and its dependencies only, you don’t need to do this step because Katalon Studio already bundles selenium-java:3.141.59.
Just copy your Java source code to Include/scripts/groovy and enjoy Katalon.

Thanks

Thank you @duyluong and @kazurayam. This was a great help!