我一直在尝试使 LeanFT html 报告与我的 Selenium/Junit 框架一起工作,但到目前为止还没有任何乐趣。我在不同的论坛上多次搜索过这个主题,包括。惠普官方资料并尝试了我能找到的所有设置方法。使用自定义 Selenium/LeanFT 框架时仍会生成 XML 运行结果文件。
我使用 JUnit 作为我的框架和 Selenium 作为 SDK 创建了一个 LeanFT 测试项目项目。我还添加了相关的硒罐。
LeanFT 版本是 14.0.2816.0。我意识到这个问题:https ://community.softwaregrp.com/t5/UFT-Practitioners-Forum/HTML-report-not-generated-in-custom-framework-using-LeanFT/td-p/1614027 。
如果有人能解释我在这里犯错的地方或者软件版本是否是这里的问题,我将不胜感激。很感谢任何形式的帮助。
实际设置包含更多抽象,通常更复杂并作为 jar 文件运行,但出于本主题的目的,我已经简化了代码,因为两种设置的结果是相同的 - runresults.xml 并且没有 html:
测试类:
import com.hp.lft.report.CaptureLevel; import com.hp.lft.report.ModifiableReportConfiguration; import com.hp.lft.report.Reporter; import com.hp.lft.sdk.ModifiableSDKConfiguration; import com.hp.lft.sdk.SDK; import com.hp.lft.sdk.web.Browser; import com.hp.lft.sdk.web.BrowserDescription; import com.hp.lft.sdk.web.BrowserFactory; import com.hp.lft.sdk.web.BrowserType; import core.Selenium; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.*; import java.io.File; import java.net.URI; public class SeleniumTest extends Selenium { WebDriver driver; Browser browser; public SeleniumTest() { //Change this constructor to private if you supply your own public constructor } @BeforeClass public static void setUpBeforeClass() throws Exception { instance = new SeleniumTest(); globalSetup(SeleniumTest.class); } @AfterClass public static void tearDownAfterClass() throws Exception { globalTearDown(); } @Before public void setUp() throws Exception { ModifiableSDKConfiguration sdkConfig = new ModifiableSDKConfiguration(); sdkConfig.setServerAddress(new URI("ws://localhost:5095")); SDK.init(sdkConfig); ModifiableReportConfiguration reportConfig = new ModifiableReportConfiguration(); reportConfig.setOverrideExisting(true); reportConfig.setTargetDirectory("C:\\Users\\user\\IdeaProjects\\LeanFT_Selenium\\RunResults"); reportConfig.setReportFolder("LastRun"); reportConfig.setTitle("Summary"); reportConfig.setDescription("Description"); reportConfig.setSnapshotsLevel(CaptureLevel.All); Reporter.init(reportConfig); ChromeOptions options = new ChromeOptions(); options.addExtensions(new File ("C:\\Program Files (x86)\\HP\\Unified Functional Testing\\Installations\\Chrome\\Agent.crx")); System.setProperty("webdriver.chrome.driver", "C:\\HP_Reporting\\Webdriver\\chromedriver.exe"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(options); browser = BrowserFactory.attach(new BrowserDescription.Builder() .type(BrowserType.CHROME).build()); } @After public void tearDown() throws Exception { driver.quit(); browser = null; Reporter.generateReport(); SDK.cleanup(); } @Test public void test() throws Exception { driver.get("https://www.google.co.uk/"); } }
硒类:
import com.hp.lft.report.Status; import com.hp.lft.unittesting.UnitTestBase; import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.rules.TestWatcher; public class Selenium extends UnitTestBase{ protected static Selenium instance; public static void globalSetup(Class<? extends Selenium> testClass) throws Exception { if (instance == null) instance = testClass.newInstance(); instance.classSetup(); } @Before public void beforeTest() throws Exception { testSetup(); } @After public void afterTest() throws Exception { testTearDown(); } public static void globalTearDown() throws Exception { instance.classTearDown(); getReporter().generateReport(); } @ClassRule public static TestWatcher classWatcher = new TestWatcher() { @Override protected void starting(org.junit.runner.Description description) { className = description.getClassName(); } }; @Rule public TestWatcher watcher = new TestWatcher() { @Override protected void starting(org.junit.runner.Description description) { testName = description.getMethodName(); } @Override protected void failed(Throwable e, org.junit.runner.Description description) { setStatus(Status.Failed); } @Override protected void succeeded(org.junit.runner.Description description) { setStatus(Status.Passed); } }; @Override protected String getTestName() { return testName; } @Override protected String getClassName() { return className; } protected static String className; protected String testName; }