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

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

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" 的错误,我不知道如何解决它(我是一个编程初学者)。

这是脚本:

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.testobject.FindTestObject as 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.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
import java.util.Arrays as Arrays
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import org.openqa.selenium.By as By
@Grab(module = 'poi', version = '4.1.2', group = 'org.apache.poi')
import org.apache.poi.ss.usermodel.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook

WebUI.openBrowser('')

WebUI.navigateToUrl('https://www.odoo.com/it_IT/web/login')

WebUI.setText(findTestObject('Object Repository/Page_Login  Odoo/input_E-mail_login'), 'EMAIL---')

WebUI.setEncryptedText(findTestObject('Object Repository/Page_Login  Odoo/input_Password_password'), 'PASS---')

WebUI.click(findTestObject('Object Repository/Page_Login  Odoo/button_Accedi'))


TestObject tableObject = findTestObject('/html/body/div[1]/main/div[1]/div/div[1]/table')

List<WebElement> righeTabella = WebUI.findWebElements(tableObject)

List<WebElement> arrayName = new ArrayList<String>()

List<WebElement> arrayEmail = new ArrayList<String>()

for (WebElement riga : righeTabella) { //ciclo per ogni riga della tabella
    WebElement link = riga.findElement(By.tagName('a')) //trova il collegamento <a> per ogni riga 
        

    WebUI.click(link) //apre il collegamento della riga
        

    WebElement nameSpan = link.findElement(By.xpath('.//span[@itemprop=\'name\']')) //Ricerco il campo span 'name'
        

    String nameText = nameSpan.getText() //copio il campo span 'name'
        

    arrayName.add(nameText) //aggiungo ad arrayName il valore del nome appena copiato
        

    WebElement emailSpan = link.findElement(By.xpath('.//span[@itemprop=\'email\']')) //Ricerco il campo span 'email'
        

    String emailText = emailSpan.getText() //copio il campo span 'email'
        

    arrayEmail.add(emailText) //aggiungo ad arrayName il valore del email appena copiato
        
}

Workbook workbook = new XSSFWorkbook()

Sheet sheet = workbook.createSheet('Dati')

for (int i = 0; i < arrayName.size(); i++) {
    // Popolamento del file Excel con i dati dell'array
    String nameExcel = arrayName.get(i)

    Row row = sheet.createRow(i)

    Cell cell1 = row.createCell(0)

    cell1.setCellValue(nameExcel)

    String emailExcel = arrayEmail.get(i)

    Cell cell2 = row.createCell(1)

    cell2.setCellValue(emailExcel)
}

// Salvataggio del file Excel
FileOutputStream fileOut = new FileOutputStream('C:/Users/orien/OneDrive/Desktop/excel-lead-odoo.xlsx')

workbook.write(fileOut)

fileOut.close()

workbook.close()

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

at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
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:

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.testobject.FindTestObject as 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.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
import java.util.Arrays as Arrays
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import org.openqa.selenium.By as By
@Grab(module = 'poi', version = '4.1.2', group = 'org.apache.poi')
import org.apache.poi.ss.usermodel.*
import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook
WebUI.openBrowser('')
WebUI.navigateToUrl('https://www.odoo.com/it_IT/web/login')
WebUI.setText(findTestObject('Object Repository/Page_Login  Odoo/input_E-mail_login'), 'EMAIL---')
WebUI.setEncryptedText(findTestObject('Object Repository/Page_Login  Odoo/input_Password_password'), 'PASS---')
WebUI.click(findTestObject('Object Repository/Page_Login  Odoo/button_Accedi'))
TestObject tableObject = findTestObject('/html/body/div[1]/main/div[1]/div/div[1]/table')
List<WebElement> righeTabella = WebUI.findWebElements(tableObject)
List<WebElement> arrayName = new ArrayList<String>()
List<WebElement> arrayEmail = new ArrayList<String>()
for (WebElement riga : righeTabella) { //ciclo per ogni riga della tabella
WebElement link = riga.findElement(By.tagName('a')) //trova il collegamento <a> per ogni riga 
WebUI.click(link) //apre il collegamento della riga
WebElement nameSpan = link.findElement(By.xpath('.//span[@itemprop=\'name\']')) //Ricerco il campo span 'name'
String nameText = nameSpan.getText() //copio il campo span 'name'
arrayName.add(nameText) //aggiungo ad arrayName il valore del nome appena copiato
WebElement emailSpan = link.findElement(By.xpath('.//span[@itemprop=\'email\']')) //Ricerco il campo span 'email'
String emailText = emailSpan.getText() //copio il campo span 'email'
arrayEmail.add(emailText) //aggiungo ad arrayName il valore del email appena copiato
}
Workbook workbook = new XSSFWorkbook()
Sheet sheet = workbook.createSheet('Dati')
for (int i = 0; i < arrayName.size(); i++) {
// Popolamento del file Excel con i dati dell'array
String nameExcel = arrayName.get(i)
Row row = sheet.createRow(i)
Cell cell1 = row.createCell(0)
cell1.setCellValue(nameExcel)
String emailExcel = arrayEmail.get(i)
Cell cell2 = row.createCell(1)
cell2.setCellValue(emailExcel)
}
// Salvataggio del file Excel
FileOutputStream fileOut = new FileOutputStream('C:/Users/orien/OneDrive/Desktop/excel-lead-odoo.xlsx')
workbook.write(fileOut)
fileOut.close()
workbook.close()
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

at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
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:448)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
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:

确定