首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium转Java

Selenium转Java
EN

Stack Overflow用户
提问于 2014-01-14 22:53:51
回答 1查看 515关注 0票数 0

我对相当陌生,并且正在经历一些我在视频和教程中没有看到的东西。

我使用Selenium记录了以下测试:在编辑配置文件信息中浏览网站日志、提交更改、验证更改

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

我甚至试着一步一步地手工操作,这似乎也很有效,但花费时间最长的部分是输入用户登录信息(用户名和密码)。

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

代码语言:javascript
复制
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;
        }
      }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-15 03:23:15

我建议你也试试硒生成器,看看它是否更适合你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21125762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档