Selenium webdriver Selenium如何打开web浏览器以运行Selenium脚本

Selenium webdriver Selenium如何打开web浏览器以运行Selenium脚本,selenium-webdriver,testng,Selenium Webdriver,Testng,我从selenium IDE 1.9.0以Java/TestNG/RemoteControl的形式导出了一个脚本 我想在Eclipse中使用TestNG运行这个脚本,我想看到脚本在Firefox浏览器中回放 我在网上做了一些搜索,但没能成功。我需要一些关于如何使代码工作的说明和指导。非常感谢你的帮助 这是我的密码: import java.util.List; import org.testng.annotations.*; import org.openqa.selenium.By; impo

我从selenium IDE 1.9.0以Java/TestNG/RemoteControl的形式导出了一个脚本

我想在Eclipse中使用TestNG运行这个脚本,我想看到脚本在Firefox浏览器中回放

我在网上做了一些搜索,但没能成功。我需要一些关于如何使代码工作的说明和指导。非常感谢你的帮助

这是我的密码:

import java.util.List;
import org.testng.annotations.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import static org.testng.Assert.*;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class search_donor_suzy_ng //extends SeleneseTestNgHelper {
    @BeforeTest
    public void setUp() throws Exception {
        //initizlize Firefoxbrowser: 
        WebDriver ffoxdriver = new FirefoxDriver();
        String baseUrl = "www.google.com"; //sample URL
    }
    @Test 
    public void testSearch_donor_suzy_ng() throws Exception {
        // set overall speed of the test case
        selenium.setSpeed("4000");
        selenium.open("/?html=openid");
        selenium.click("css=input[type=\"submit\"]");
        selenium.waitForPageToLoad("30000");
        Thread.sleep(4000);
        selenium.type("id=edit-name", "jeffshu");
        selenium.type("id=edit-pass", "tEgvz9xsaNjnwe4Y");
        selenium.click("id=edit-submit");
        selenium.waitForPageToLoad("30000");
        Thread.sleep(4000);
        selenium.click("id=cmp_admin");
        selenium.waitForPageToLoad("30000");
        selenium.click("id=quicksearch_anchor");
        selenium.click("css=img[alt=\"Member\"]");
        selenium.waitForPageToLoad("30000");
        selenium.type("id=search_name", "suzy");
        selenium.click("css=input[type=\"image\"]");
        selenium.click("link=Balagia, Suzy");
        selenium.waitForPageToLoad("30000");
    }
    @AfterTest
    public void tearDown() throws Exception {
        ffoxdriver.quit();  
    }
} 

对于初学者,您确实需要参考文档@

在代码中,您正在初始化beforetest方法中的驱动程序对象,但未使用该方法。Driver是Webdriver启动浏览器的方式,而在testmethod中,您使用的是selenium和selenium 1命令。作为一个快速步骤,您可以用驱动程序替换selenium(将驱动程序声明放在类范围和方法范围中)。SeleneseTestngHelper也是selenium1。 确保项目中有必要的webdriver JAR


webdriver中的某些命令与selenium 1不同,在进行替换时,您可能会看到编译错误。查看驱动程序可用的方法。并使用相应的命令,例如使用webdriver的get()而不是open()。您可以参考或使用ide了解这些信息。

@user1177636,谢谢您的回复。我将阅读有关Selenium RC的Selenium文档。你能告诉我为什么你推荐Webdriver而不是Selenium RC吗?谢谢您好,user1177636,我将Selenium 1代码导出为Junit/WebDriver,并做了一些修改,它成功了。谢谢你的建议!感谢您的建议,我将代码导出为Junit4/WedDriver,并以Junit test的形式运行代码,其工作方式与我从Selenium IDE执行脚本的方式相同。谢谢