Katalon Studio: 无法解析类 com.kms.katalon.core.testobject.FindTestObject 作为 FindTestObject

huangapple go评论90阅读模式
英文:

Katalon Studio: unable to resolve class com.kms.katalon.core.testobject.FindTestObject as FindTestObject

问题

我已经编写了一个网页抓取脚本,它应该从一个平台复制数据并将这些数据写入一个新的Excel文件。Katalon 给我一个关于类 "import com.kms.katalon.core.testobject.FindTestObject as FindTestObject" 的错误,我不知道如何解决它(我是一个编程初学者)。

这是脚本:

  1. import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
  2. import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
  3. import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
  4. import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
  5. import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
  6. import com.kms.katalon.core.testobject.FindTestObject as FindTestObject
  7. import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
  8. import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
  9. import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
  10. import com.kms.katalon.core.model.FailureHandling as FailureHandling
  11. import com.kms.katalon.core.testcase.TestCase as TestCase
  12. import com.kms.katalon.core.testdata.TestData as TestData
  13. import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
  14. import com.kms.katalon.core.testobject.TestObject as TestObject
  15. import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
  16. import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
  17. import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
  18. import internal.GlobalVariable as GlobalVariable
  19. import org.openqa.selenium.Keys as Keys
  20. import java.util.Arrays as Arrays
  21. import org.openqa.selenium.WebElement as WebElement
  22. import com.kms.katalon.core.testobject.ConditionType as ConditionType
  23. import com.kms.katalon.core.testobject.TestObject as TestObject
  24. import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
  25. import org.openqa.selenium.By as By
  26. @Grab(module = 'poi', version = '4.1.2', group = 'org.apache.poi')
  27. import org.apache.poi.ss.usermodel.*
  28. import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook
  29. WebUI.openBrowser('')
  30. WebUI.navigateToUrl('https://www.odoo.com/it_IT/web/login')
  31. WebUI.setText(findTestObject('Object Repository/Page_Login Odoo/input_E-mail_login'), 'EMAIL---')
  32. WebUI.setEncryptedText(findTestObject('Object Repository/Page_Login Odoo/input_Password_password'), 'PASS---')
  33. WebUI.click(findTestObject('Object Repository/Page_Login Odoo/button_Accedi'))
  34. TestObject tableObject = findTestObject('/html/body/div[1]/main/div[1]/div/div[1]/table')
  35. List<WebElement> righeTabella = WebUI.findWebElements(tableObject)
  36. List<WebElement> arrayName = new ArrayList<String>()
  37. List<WebElement> arrayEmail = new ArrayList<String>()
  38. for (WebElement riga : righeTabella) { //ciclo per ogni riga della tabella
  39. WebElement link = riga.findElement(By.tagName('a')) //trova il collegamento <a> per ogni riga
  40. WebUI.click(link) //apre il collegamento della riga
  41. WebElement nameSpan = link.findElement(By.xpath('.//span[@itemprop=\'name\']')) //Ricerco il campo span 'name'
  42. String nameText = nameSpan.getText() //copio il campo span 'name'
  43. arrayName.add(nameText) //aggiungo ad arrayName il valore del nome appena copiato
  44. WebElement emailSpan = link.findElement(By.xpath('.//span[@itemprop=\'email\']')) //Ricerco il campo span 'email'
  45. String emailText = emailSpan.getText() //copio il campo span 'email'
  46. arrayEmail.add(emailText) //aggiungo ad arrayName il valore del email appena copiato
  47. }
  48. Workbook workbook = new XSSFWorkbook()
  49. Sheet sheet = workbook.createSheet('Dati')
  50. for (int i = 0; i < arrayName.size(); i++) {
  51. // Popolamento del file Excel con i dati dell'array
  52. String nameExcel = arrayName.get(i)
  53. Row row = sheet.createRow(i)
  54. Cell cell1 = row.createCell(0)
  55. cell1.setCellValue(nameExcel)
  56. String emailExcel = arrayEmail.get(i)
  57. Cell cell2 = row.createCell(1)
  58. cell2.setCellValue(emailExcel)
  59. }
  60. // Salvataggio del file Excel
  61. FileOutputStream fileOut = new FileOutputStream('C:/Users/orien/OneDrive/Desktop/excel-lead-odoo.xlsx')
  62. workbook.write(fileOut)
  63. fileOut.close()
  64. workbook.close()
  65. WebUI.closeBrowser()

这是错误信息:

Test Cases/Test 1 lead odoo FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/orien/Katalon%20Studio/Odoo%20leads/Scripts/Test%201%20lead%20odoo/Script1687957429899.groovy: 8: unable to resolve class com.kms.katalon.core.testobject.FindTestObject
@ line 8, column 1.
import com.kms.katalon.core.testobject.FindTestObject as FindTestObject
^

1 error

  1. at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
  2. at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
  3. at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
  4. at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
  5. at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
  6. at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
  7. at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
  8. at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
  9. at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
  10. at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
  11. at com.kms.k
英文:

I have written a scraping script which its supposed to copy data from one platform and write this data to a new excel. Katalon gives me an error about the class "import com.kms.katalon.core.testobject.FindTestObject as FindTestObject" and I don't know how to solve it (I am a beginner in programming).

This is the script:

  1. import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
  2. import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
  3. import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
  4. import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
  5. import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
  6. import com.kms.katalon.core.testobject.FindTestObject as FindTestObject
  7. import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
  8. import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
  9. import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
  10. import com.kms.katalon.core.model.FailureHandling as FailureHandling
  11. import com.kms.katalon.core.testcase.TestCase as TestCase
  12. import com.kms.katalon.core.testdata.TestData as TestData
  13. import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
  14. import com.kms.katalon.core.testobject.TestObject as TestObject
  15. import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
  16. import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
  17. import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
  18. import internal.GlobalVariable as GlobalVariable
  19. import org.openqa.selenium.Keys as Keys
  20. import java.util.Arrays as Arrays
  21. import org.openqa.selenium.WebElement as WebElement
  22. import com.kms.katalon.core.testobject.ConditionType as ConditionType
  23. import com.kms.katalon.core.testobject.TestObject as TestObject
  24. import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
  25. import org.openqa.selenium.By as By
  26. @Grab(module = 'poi', version = '4.1.2', group = 'org.apache.poi')
  27. import org.apache.poi.ss.usermodel.*
  28. import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook
  29. WebUI.openBrowser('')
  30. WebUI.navigateToUrl('https://www.odoo.com/it_IT/web/login')
  31. WebUI.setText(findTestObject('Object Repository/Page_Login Odoo/input_E-mail_login'), 'EMAIL---')
  32. WebUI.setEncryptedText(findTestObject('Object Repository/Page_Login Odoo/input_Password_password'), 'PASS---')
  33. WebUI.click(findTestObject('Object Repository/Page_Login Odoo/button_Accedi'))
  34. TestObject tableObject = findTestObject('/html/body/div[1]/main/div[1]/div/div[1]/table')
  35. List<WebElement> righeTabella = WebUI.findWebElements(tableObject)
  36. List<WebElement> arrayName = new ArrayList<String>()
  37. List<WebElement> arrayEmail = new ArrayList<String>()
  38. for (WebElement riga : righeTabella) { //ciclo per ogni riga della tabella
  39. WebElement link = riga.findElement(By.tagName('a')) //trova il collegamento <a> per ogni riga
  40. WebUI.click(link) //apre il collegamento della riga
  41. WebElement nameSpan = link.findElement(By.xpath('.//span[@itemprop=\'name\']')) //Ricerco il campo span 'name'
  42. String nameText = nameSpan.getText() //copio il campo span 'name'
  43. arrayName.add(nameText) //aggiungo ad arrayName il valore del nome appena copiato
  44. WebElement emailSpan = link.findElement(By.xpath('.//span[@itemprop=\'email\']')) //Ricerco il campo span 'email'
  45. String emailText = emailSpan.getText() //copio il campo span 'email'
  46. arrayEmail.add(emailText) //aggiungo ad arrayName il valore del email appena copiato
  47. }
  48. Workbook workbook = new XSSFWorkbook()
  49. Sheet sheet = workbook.createSheet('Dati')
  50. for (int i = 0; i < arrayName.size(); i++) {
  51. // Popolamento del file Excel con i dati dell'array
  52. String nameExcel = arrayName.get(i)
  53. Row row = sheet.createRow(i)
  54. Cell cell1 = row.createCell(0)
  55. cell1.setCellValue(nameExcel)
  56. String emailExcel = arrayEmail.get(i)
  57. Cell cell2 = row.createCell(1)
  58. cell2.setCellValue(emailExcel)
  59. }
  60. // Salvataggio del file Excel
  61. FileOutputStream fileOut = new FileOutputStream('C:/Users/orien/OneDrive/Desktop/excel-lead-odoo.xlsx')
  62. workbook.write(fileOut)
  63. fileOut.close()
  64. workbook.close()
  65. WebUI.closeBrowser()

And this is the error:

Test Cases/Test 1 lead odoo FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/orien/Katalon%20Studio/Odoo%20leads/Scripts/Test%201%20lead%20odoo/Script1687957429899.groovy: 8: unable to resolve class com.kms.katalon.core.testobject.FindTestObject
@ line 8, column 1.
import com.kms.katalon.core.testobject.FindTestObject as FindTestObject
^

1 error

  1. at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
  2. at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
  3. at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
  4. at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
  5. at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
  6. at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
  7. at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
  8. at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
  9. at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
  10. at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
  11. at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
  12. at TempTestCase1689002556348.run(TempTestCase1689002556348.groovy:25)

I tried to import the class in "build.gradle" but nothing changed.

答案1

得分: 1

所需的类com.kms.katalon.core.testobject.FindTestObject在脚本中似乎无法识别。

尝试通过检查以下要点来解决问题:

  1. 确保你在你的requirements.txt文件(位于src/user目录中)或在__manifest__.py文件(位于你的自定义模块内)的"external_dependencies"部分中列出了必要的Katalon Studio库com.kms.katalon.core.testobject。你可以检查项目的依赖项或库配置,以确保包括所需的库。

  2. 检查Katalon Studio文档,确保它已正确安装和配置。

  3. 检查你正在使用的Katalon Studio版本与你导入的库之间的版本兼容性。版本不兼容可能会引发问题。

英文:

The required class com.kms.katalon.core.testobject.FindTestObject seems not being recognized by the script.

Try to resolve the issue by checking the following points:

  1. Make sure you have the necessary Katalon Studio libraries com.kms.katalon.core.testobject are listed in your requirements.txt file (located in the src/user directory) or in the section: "external_dependencies" in the __manifest__.py file (located inside your custom module). You can check the project's dependencies or libraries configuration to ensure that the required libraries are included.

  2. Check the Katalon Studio documentation to ensure that it is properly installed and configured.

  3. Check the version compatibility between the Katalon Studio version you are using and the libraries you are importing. Incompatibility between versions can cause issues.

huangapple
  • 本文由 发表于 2023年7月10日 23:44:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定