Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
seleniumide到Java_Java_Selenium_Junit_Automation_Selenium Webdriver - Fatal编程技术网

seleniumide到Java

seleniumide到Java,java,selenium,junit,automation,selenium-webdriver,Java,Selenium,Junit,Automation,Selenium Webdriver,我对Selenium自动化测试还相当陌生,并且正在经历一些我在视频和教程中看不到的事情 我使用Selenium IDE记录了以下各项的测试: 浏览网站 登录 编辑配置文件信息 提交更改 验证更改 当我在Firefox中重播它时,它工作得很好。我的问题是,当我将其导出到Java-Junit Webdriver并通过Eclipse运行测试时,需要花费很长的时间来完成这些步骤,从而导致失败或整体失败 我甚至试着一步一步地手工操作,这似乎也能奏效,但最耗时的部分是输入用户登录信息(用户名和密码) 这个新

我对Selenium自动化测试还相当陌生,并且正在经历一些我在视频和教程中看不到的事情

我使用Selenium IDE记录了以下各项的测试: 浏览网站 登录 编辑配置文件信息 提交更改 验证更改

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

我甚至试着一步一步地手工操作,这似乎也能奏效,但最耗时的部分是输入用户登录信息(用户名和密码)

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

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;
        }
      }
}

我建议你也试着看看这是否对你更有效