LeanFT和Java:在Docker容器中运行测试
我的基于Java的LeanFT测试在使用IntelliJ,JUnit和LeanFT的本地计算机上运行良好:

Chrome打开,我看到测试正在运行,一切正常。

现在,我想在Docker容器中运行这些测试。

当我的测试仅进行简单的导航时,一切都可以:

@test
public void simpleTest2() throws GeneralLeanFtException {

    browser.navigate("https://www.google.com");

}

Docker启动,获得LeanFt许可证并运行测试:
dev@ubuntu:~$ docker run -p 5900:5900 -v /home/dev/development/tempprojects/LeanFT_1/target:/tests --env LFT_LIC_SERVER=S021000105693b.adr.admin.ch --env LFT_LIC_ID=10594 --env RUN_MODE=junit --env RUN_CMD=ch.admin.bit.LeanFtTest -t -i -w /tests functionaltesting/leanft-chrome


LeanFT runtime engine started successfully
License: Concurrent UFT Enterprise Concurrent User
Port: 5095
Version: 14.3.546, (c) Copyright 2015 EntIT Software LLC
Installation Folder: /opt/leanft
Executing junit test: ch.admin.bit.LeanFtTest
JUnit version 4.12
.
Time: 5.778

OK (1 test)

LeanFT runtime engine has stopped successfully

问题:

当我将WebElement添加到测试中时,它不起作用(在IntelliJ中,它可与LeanFT-Runner一起使用)

像这样:
Menu dEFRITENMenu = browser.describe(Menu.class, new MenuDescription.Builder()
.accessibilityName("")
.id("")
.role("menu")
.tagName("UL")
.index(1).build());
dEFRITENMenu.select("EN");

错误是:
1) simpleTest(ch.admin.bit.LeanFtTest)
com.hp.lft.sdk.ReplayObjectNotFoundException: Cannot identify the object "Web Menu".
Verify that this object's properties match an object currently displayed in your application.
at com.hp.lft.sdk.internal.ReplayExceptionFactory$1.create(ReplayExceptionFactory.java:34)
at com.hp.lft.sdk.internal.ReplayExceptionFactory.createOrDefault(ReplayExceptionFactory.java:197)
at com.hp.lft.sdk.internal.ReplayExceptionFactory.createOrDefault(ReplayExceptionFactory.java:21)
at com.hp.lft.sdk.internal.TestObjectExecuterBehaviorBase$ReplayErrorHandler.onError(TestObjectExecuterBehaviorBase.java:65)
at com.hp.lft.sdk.internal.CommunicationClientImpl.handleError(CommunicationClientImpl.java:221)
at com.hp.lft.sdk.internal.CommunicationClientImpl.send(CommunicationClientImpl.java:96)
at com.hp.lft.sdk.internal.TestObjectExecuterBehavior.executeMethod(TestObjectExecuter.java:33)
at com.hp.lft.sdk.internal.TestObjectBase.executeMethod(TestObjectBase.java:119)
at com.hp.lft.sdk.internal.web.WebMenu.access$100(WebMenu.java:14)
at com.hp.lft.sdk.internal.web.WebMenu$2.invoke(WebMenu.java:52)
at com.hp.lft.sdk.internal.TestObjectOperationWrapper.executeWithEvents(TestObjectOperationWrapper.java:81)
at com.hp.lft.sdk.internal.TestObjectOperationWrapper.executeWithEvents(TestObjectOperationWrapper.java:102)
at com.hp.lft.sdk.internal.web.WebMenu.select(WebMenu.java:56)
at ch.admin.bit.LeanFtTest.simpleTest(LeanFtTest.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)

有没有人有主意或正在运行的例子?

最佳答案

该元素真的存在吗?

要调试答案,请尝试仅使用browser.getPage().getText()并使用Reporter api报告值,或者使用println值或其他方式。在browser.navigate之后执行此操作,如果它可以工作,则它应可用于其他任何LeanFT命令。

您甚至可以描述html的正文并记录innerHTML值,如下所示:

WebElement htmlBody = browser.describe(WebElement.class, new WebElementDescription.Builder().tagName("BODY").build());
htmlBody.getInnerHTML();

是否启用了浏览器扩展?

启动可以在启用或不启用浏览器扩展的情况下运行,但要执行复杂的操作,您需要启用LeanFT浏览器代理。

它是正确的描述吗?

如我所见,初始描述需要:
  • no accesibilityName
  • no id
  • "menu"角色,
  • 一个<ul>元素
  • index必须为1

  • 如果索引是2怎么办?您是否100%确定所有浏览器/所有计算机上的索引都相同?如果它不是Menu元素怎么办?如果改用WebElement,上述说明是否有效?

    尝试消除具有错误值的风险,并将描述限制为您知道100%不会因浏览器而改变的内容。

    使用对象识别中心可以在此方向上提供很多帮助。

    您是否对以上所有问题回答是?

    好吧,LeanFT在这种情况下可以工作,但效果不如预期。在这种情况下,可能是LeanFT错误。

    09-17 15:00