I have been trying to make LeanFT html reports work with my Selenium/Junit framework, however so far without any joy. I have searched the topic multiple times on different forums incl. HP official materials and tried all setup methods that I could find. An XML runresults file is still generated when using a custom Selenium/LeanFT framework.
I create a LeanFT Testing Project project using JUnit as my framework and Selenium as SDK. I also add relevant Selenium jars.
LeanFT version is 14.0.2816.0. I am conscious of this issue: https://community.softwaregrp.com/t5/UFT-Practitioners-Forum/HTML-report-not-generated-in-custom-framework-using-LeanFT/td-p/1614027 .
I would be grateful, if someone could explain where I am making a mistake here or if the software version is the problem here. Any help is very much appreciated.
The actual setup contains more abstractions, is generally more complex and runs as a jar file, but I have simplified the code for the purpose of this topic as the outcome of both setups is the same - a runresults.xml and no html:
Test Class:
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/"); } }
Selenium Class:
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; }