【问题标题】:How can I make Selenium tests inside my JSF project?如何在我的 JSF 项目中进行 Selenium 测试?
【发布时间】:2013-05-23 06:47:31
【问题描述】:

我有一个相当大的 JSF 1.2 项目,我想为它编写一些集成测试。 完美的情况是,当我可以从我的项目中运行这些测试时,它会打开我的浏览器并执行所有操作(使用 Selenium),这些操作都是在我的测试用例中编写的。当它无论如何都会运行这些测试时,不需要打开浏览器:)

我尝试了几种可能性,但我仍然无法将任何 selenium 库附加到我的项目中,我意识到我只是不知道从哪里开始 - 你能给我一些指导吗?

【问题讨论】:

  • 你想做什么样的测试? Selenium 是用于 UI 测试的,你真的需要一个浏览器。如果您不需要浏览器,则可以使用 JUnit 和 Mockito 进行单元测试。问候,

标签: jsf testing selenium integration-testing


【解决方案1】:

可能对你有帮助, 您可以在测试方法中编写测试逻辑

package com.test;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

import static org.junit.Assert.fail;

public class test1 {
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();
    @Before
    public void setUp() throws Exception {
    driver = new InternetExplorerDriver();
        driver = new ChromeDriver();
        baseUrl = "http://www.google.com";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Ignore
    @Test
    public void test1() throws Exception {
        // your test code 

    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }
}

你只需要调用你想测试它的 test1 类。 它会自动处理它。

【讨论】:

  • 我也有同样的问题。你能提供任何参考/教程吗?
猜你喜欢
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
相关资源
最近更新 更多