jsf - 如何在我的 JSF 项目中进行 Selenium 测试?

标签 jsf testing selenium integration-testing

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

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

最佳答案

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

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类即可。 它会自动处理它。

关于jsf - 如何在我的 JSF 项目中进行 Selenium 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16707300/

相关文章:

android - 数据传递到 Android 中的另一个应用程序

Selenium IDE,要上传的文件路径是相对的。

jsf - CDI bean 构造函数和@PostConstruct 多次调用

java - h :commandButton works from the second click

java - 在 div、selenium java eclipse 中找不到输入元素

php - 可以在尝试运行任何东西之前检查步骤是否已定义吗?

go - 你如何在 GoLang 的模拟中模拟错误返回值?

css - 仅将 CSS 类应用于父级(当前)p :panelGrid

jsf - 使用 OcpSoft rewrite Join.path 规则重写 URL

python - 如何为 Django 管理页面的功能编写测试?