java - 测试 Selenium Jenkins

标签 java selenium

我想在 Jenkins 中运行我的测试 Selenium 。我使用 Maven 和 Testng 在 jenkins 中运行我的测试。我有一个简单的配置来做到这一点:

package Testselenium;

import org.openqa.selenium.By;      
import org.openqa.selenium.WebDriver;       
import org.openqa.selenium.firefox.FirefoxDriver;       
import org.testng.Assert;
import org.testng.annotations.Test; 
import org.testng.annotations.BeforeTest;   
import org.testng.annotations.AfterTest;

public class NewTest {      
        private WebDriver driver;       
        @Test              
        public void testEasy() {    
            driver.get("http://localhost");  
            String title = driver.getTitle();                
            Assert.assertTrue(title.contains("TimDevOps"));   
        }   
        @BeforeTest
        public void beforeTest( ) {  
            driver = new FirefoxDriver();  
        }       
        @AfterTest
        public void afterTest() {
            driver.close();          
        }       
}   

我想配置与 Selenium IDE 中所做的相同的测试,但是当我提取 java 文件并替换上面的配置时,它不起作用:

package com.example.tests;

import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class test extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("http://localhost/", "*chrome");
    }
    public void testTest() throws Exception {
        selenium.open("/");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");
    }
}

Eclipse 不知道 selenium 对象。

有人知道如何混合这两个文件吗?预先感谢您

最佳答案

我不确定我是否理解您的问题。但我猜这就是你想要的。

package Testselemium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.thoughtworks.selenium.*;


public class NewTest extends SeleneseTestCase {
    private WebDriver driver;

    @Test
    public void testEasy() {
        driver.get("http://localhost");
        String title = driver.getTitle();
        Assert.assertTrue(title.contains("TimDevOps"));
    }

    @Test

    public void testTest() throws Exception {
        selenium.open("/");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");
        selenium.click("css=input[type=\"button\"]");

    }
    @BeforeTest
    public void beforeTest() {
        driver = new FirefoxDriver();
    }
    @AfterTest
    public void afterTest () {
        driver.close();
    }
}

关于java - 测试 Selenium Jenkins ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37294950/

相关文章:

java - 如何在低于 21 的 Android API 中使用 VectorDrawables?

java - Java JRE 的安装基础?

java - AES 256-CBC 上的 key 和 iv 问题

selenium - 使用 selenium Webdriver 在页面上选择日期

python - 如何配置 pytest 在生成测试时生成有用的名称?

java - 简单的 java swing 导致操作系统崩溃

java - 无法将照片从相机上传到服务器。非法参数异常 : column '_data' does not exist

selenium - 在哪里可以找到 Selenium Webdriver 发行说明?

jquery - 如何使用 Splinter 单击存在但不可见的复选框? ( Selenium / python )

java - 无法在 Selenium 中输入任何文本