【问题标题】:Selenium IDE to Java [closed]Selenium IDE 到 Java [关闭]
【发布时间】:2014-01-14 22:53:51
【问题描述】:

我对 Selenium 自动化测试相当陌生,并且正在体验一些我在视频和教程中看不到的东西。

我使用 Selenium IDE 记录了一个测试: 浏览网站 在登录 编辑个人资料信息 提交更改 验证更改

当我在 Firefox 中重放它时它工作正常。我的问题是,当我将它导出到 Java - Junit Webdriver 并通过 Eclipse 运行测试时,需要很长时间才能完成这些步骤,从而导致失败或整体失败。

我什至尝试一步一步地手动完成,这似乎也有效,但最耗时的部分是输入用户登录信息(用户名和密码)。

这个新手有什么不知道的吗? 导出的 IDE 在通过 Eclipse Junit 运行时是否应该“开箱即用”?

package Profile;

import java.util.concurrent.TimeUnit;

import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ProfileChangeTestCase {
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();


  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://gaming.twlstaging.com/";
  }

  @Test
  public void testOpen() throws Exception {
    driver.get(baseUrl);
    //Click LogIn
    driver.findElement(By.className("logged-out")).click();
    //Enter User name
    driver.findElement(By.xpath("//input[@id='login']")).clear();
    driver.findElement(By.xpath("//input[@id='login']")).sendKeys("Demo");
    //Enter Password
    driver.findElement(By.xpath("//input[@id='login_password']")).clear();
    driver.findElement(By.xpath("//input[@id='login_password']")).sendKeys("Blam!");
    //Click LogIn Button
    driver.findElement(By.className("login-button")).click();
    //Security Alert - Selecting continue
    Alert alert = driver.switchTo().alert();
    alert.accept();
    //Buffer for page to load
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    //Verify user name login by echo name to console
    String text = driver.findElement(By.className("user-name")).getText();
    System.out.println("Username is :" + text);
    //Buffer for contents to load
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    //Click on Edit Profile
    driver.findElement(By.xpath("//div[@id='user-navigation']/ul/li[2]/a")).click();
    //Change description in profile
    driver.findElement(By.name("interests")).clear();
    driver.findElement(By.name("interests")).sendKeys("This was done in Selenium Eclipse");
    //Update Profile
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();


  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }
  private boolean isAlertPresent() {
        try {
          driver.switchTo().alert();
          return true;
        } catch (NoAlertPresentException e) {
          return false;
        }
      }
}

【问题讨论】:

    标签: java selenium junit automation selenium-webdriver


    【解决方案1】:

    我建议你也试试Selenium Builder,看看它是否更适合你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多