使用Java在Selenium WebDriver中创建可执行文件

Shu*_*oul 8 java eclipse testing selenium-webdriver

是否可以在java中制作Selenium WebDriver可执行文件?我用java编写了代码,用于使用Selenium WebDriver进行数据驱动测试.我想把它变成可执行文件,以便外部eclipse可以执行它.

package pkg;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LogingS {
  private WebDriver driver;
  private String baseUrl;

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://www.example.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testLogingS() throws Exception {
    driver.get(baseUrl);
    System.out.println("The current Url: " + driver.getCurrentUrl());
    driver.findElement(By.id("id_email")).clear();
    driver.findElement(By.id("id_email")).sendKeys("com");
    Thread.sleep(1000);
    driver.findElement(By.id("id_password")).clear();
    driver.findElement(By.id("id_password")).sendKeys("123");
    Thread.sleep(1000);
    System.out.println("The current Url: " + driver.getCurrentUrl());
    driver.findElement(By.id("btn_login")).submit();
    Thread.sleep(5000);
    System.out.println("The current Url: " + driver.getCurrentUrl());

  }

  @After
  public void tearDown() throws Exception {

  }
}
Run Code Online (Sandbox Code Playgroud)

rsu*_*dha 0

您是否尝试过使用 ant 脚本来运行测试用例,我假设您已经使用 Junit 编写了测试用例。

谢谢!