Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LeanFT&;Selenium自定义自动化框架-未生成HTML报告_Java_Selenium_Leanft - Fatal编程技术网

Java LeanFT&;Selenium自定义自动化框架-未生成HTML报告

Java LeanFT&;Selenium自定义自动化框架-未生成HTML报告,java,selenium,leanft,Java,Selenium,Leanft,我一直在尝试让LeanFT html报告与我的Selenium/Junit框架一起工作,但是到目前为止还没有任何乐趣。 我在不同的论坛(包括HP官方资料)上多次搜索该主题,并尝试了我能找到的所有设置方法。 使用自定义Selenium/LeanFT框架时,仍会生成XML运行结果文件 我创建了一个LeanFT测试项目,使用JUnit作为我的框架,Selenium作为SDK。我还添加了相关的硒罐 LeanFT版本为14.0.2816.0。 我意识到这个问题: 如果有人能解释我在这里犯了什么错误,或者软

我一直在尝试让LeanFT html报告与我的Selenium/Junit框架一起工作,但是到目前为止还没有任何乐趣。 我在不同的论坛(包括HP官方资料)上多次搜索该主题,并尝试了我能找到的所有设置方法。 使用自定义Selenium/LeanFT框架时,仍会生成XML运行结果文件

我创建了一个LeanFT测试项目,使用JUnit作为我的框架,Selenium作为SDK。我还添加了相关的硒罐

LeanFT版本为14.0.2816.0。 我意识到这个问题:

如果有人能解释我在这里犯了什么错误,或者软件版本是否是问题所在,我将不胜感激。非常感谢任何帮助

实际的设置包含更多的抽象,通常更复杂,并且作为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;
    
    
    
    }
    
    import com.hp.lft.report.Status;
    导入com.hp.lft.unittesting.UnitTestBase;
    导入org.junit.After;
    导入org.junit.Before;
    导入org.junit.ClassRule;
    导入org.junit.Rule;
    导入org.junit.rules.TestWatcher;
    公共类Selenium扩展了UnitTestBase{
    受保护的静态实例;
    公共静态无效全局设置(类TL;DR
    该报告仅在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();
      
    当您使用内置模板时,您会注意到会自动创建一个从
    UnitTestBase
    扩展而来的
    UnitTestClassBase
    类,并且您的
    leanftest
    类从该
    UnitTestClassBase
    扩展而来

    通过这样做,您将以一种非常特定的方式初始化
    SDK
    Reporter
    ,这就是通过此初始化生成HTML报告的原因。如果要在自定义框架中以这种特定的方式复制,您还将生成HTML报告。如果您感到好奇,可以检查内容查看它的功能

    您正在从UnitTestBase进行扩展。为什么它不起作用?

    正如我在评论中提到的,实际上您正在两次执行
    SDK
    Reporter
    初始化,一次是通过扩展
    UnitTestBase
    (如上所述,它已经进行了初始化),第二次是在
    设置
    方法中

    由于您使用的是LeanFT 14.00,因此应让
    UnitTestBase
    进行初始化、清理和报告生成。这意味着您的测试类文件应更改为不再包含
    SDK
    Reporter
    的init,如下所示:

    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和报告。如何在LeanFT 14.00中实现这一点?

    SDK
    Reporter
    可以通过两种方式进行配置:

  • 初始化时,当您试图通过
    ModifiableSDKConfiguration
    ModifiableReportConfiguration
  • 在测试设置文件(
    resources/leanft.properties
    )中。您可以看到
  • 您也可以在运行时通过
    Reporter
    API操作某些报表设置:

    • 设置报告级别:
      Reporter.setReportLevel(ReportLevel.All);
    • 设置快照捕获级别
      Reporter.setSnapshotCaptureLevel(CaptureLevel.All);
    • 即使通过基类初始化了
      SDK
      Reporter
      ,也可以在报表中添加自定义报表事件(这些工作:
      Reporter.reportEvent();
      Reporter.startReportingContext();
      Reporter.startTest();
      ,等等)

    (1)
    UnitTestBase
    SDK
    Reporter
    已经初始化了,因此在测试类中也进行了初始化,您将进行两次。如果您不想在
    Selenium
    类中进行初始化,只需删除
    扩展UnitTestBase
    位即可。(2)您说您知道在14.00中,报告不是使用定制框架生成的(这意味着您自己初始化并生成它)然而,你在这里,做着完全相同的事情。谢谢你的投入。是的,我知道这一点,但是我认为也许有一种方法可以解决它,或者人们有不同的经验。你自己初始化和生成html是什么意思?而且我相信,如果没有,必须引入可修改的sdk和init使用本机LeanFT sdk,所以我认为Selenium中的sdk和reporter是为了引入新的可修改sdk和可修改reporter,而不是复制UnitTestBase。如果明天之前没有人回答,我将自己给出一个全面的答案。FWIW,我们已经放弃了尽可能多的LeanFT框架,以便我们有更多的灵活性这对于新的测试项目很有用