我一直试图让LeanFT html报告与我的Selenium / Junit框架一起工作,但到目前为止没有任何乐趣。 我在不同的论坛上多次搜索该主题。 HP官方资料并尝试了我能找到的所有设置方法。 使用自定义Selenium / LeanFT框架时仍会生成XML runresults文件。
我创建了一个LeanFT Testing Project项目,使用JUnit作为我的框架,Selenium作为SDK。我还添加了相关的Selenium罐子。
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/");
}
}
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;
}
答案 0 :(得分:1)
报告仅在14.00时通过扩展UnitTestBase
生成。要使用自定义自动化框架生成报告,您必须至少升级到LeanFT 14.01(写入时最新版本为14.02)。
哦,只是为了澄清:这个问题与Selenium无关。例如,您在使用NUnit 3的C#LeanFT SDK中具有相同的行为。
在此上下文中什么是自定义自动化框架?
当我说自定义自动化框架时,我指的是执行SDK
和Reporter
初始化和清理的任何框架。
LeanFT通过其引擎完成所有魔术。要告诉自定义框架连接到引擎,您需要执行以下步骤:
在测试套件的开头:
SDK.init();
Reporter.init(); // This is not for the engine, but for the HTML report generation
在测试套件的末尾
Reporter.generateReport();
SDK.cleanup();
当您使用内置模板时,您会注意到自动创建了UnitTestClassBase
类,该类从UnitTestBase
延伸,并且您的LeanFtTest
类从此{{1}延伸}}
通过这样做,您将以非常具体的方式初始化UnitTestClassBase
和SDK
,这就是为什么在此初始化时生成HTML报告的原因。如果您要在自定义框架中重现此特定方式,则还会生成HTML报告。如果您很好奇,可以查看Reporter
文件的内容以查看它的作用。
您正在从UnitTestBase扩展。为什么不起作用?
正如我的评论中所提到的,你实际上是在进行两次UnitTestBase.class
和SDK
初始化,一次是通过扩展Reporter
(正如我上面所描述的,已经进行了初始化)以及UnitTestBase
方法中的第二次。
由于您使用的是LeanFT 14.00,因此您应该让setUp
进行初始化,清理和报告生成。这意味着您的测试类文件应更改为不再包含UnitTestBase
和SDK
的初始化,如下所示:
Reporter
}
但我需要配置SDK和报告。如何在LeanFT 14.00中实现这一目标?
可以通过两种方式配置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 {
/*
This will not work in LeanFT 14.00, so we are commenting it out
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/");
}
和SDK
:
Reporter
和ModifiableSDKConfiguration
或
ModifiableReportConfiguration
)中。您可以看到plenty details in the official help。您也可以通过resources/leanft.properties
API在运行时操作某些报告设置:
Reporter
Reporter.setReportLevel(ReportLevel.All);
Reporter.setSnapshotCaptureLevel(CaptureLevel.All);
和SDK
,您仍然可以在报告中添加自定义报告事件(这些工作:Reporter
,Reporter.reportEvent();
,Reporter.startReportingContext();
等。)