搜档网
当前位置:搜档网 › MyEclipse下使用TestNG调用Selenium JAVA代码使用

MyEclipse下使用TestNG调用Selenium JAVA代码使用

MyEclipse下使用TestNG调用Selenium JAVA代码使用
MyEclipse下使用TestNG调用Selenium JAVA代码使用

在MyEclipse中安装testng插件。

在FireFox中启动Selenium IDE,录制。

录制完成后的testng代码(junit、C#等代码是有服务器初始化的)没有初始化,需要手工添加。

修改后的TestNG代码如下图所示:

public class SeleniumTest {

@Test

public void testTest() throws Exception {

S tring url="https://www.sodocs.net/doc/b47167098.html,";

S elenium selenium =new DefaultSelenium("localhost", 4444, "chrome", url); //chrome是firefox

s elenium.start();

selenium.open("/");

selenium.type("kw", "hyddd");

selenium.click("su");

selenium.waitForPageToLoad("30000");

selenium.click("//table[@id='1']/tbody/tr/td/a/font/em");

selenium.stop();

}

}

在MyEclipse执行前先启动Selenium 服务器。

命令行方式:

G:\selenium-2.0b1>java –jar selenium-server-standalone-2.01b1.jar

启动后界面如下图所示:

09:58:37.281 INFO - Java: Sun Microsystems Inc. 1.6.0-b105

09:58:37.296 INFO - OS: Windows XP 5.1 x86

09:58:37.296 INFO - v2.0 [b1], with Core v2.0 [b1]

09:58:37.421 INFO - RemoteWebDriver instances should connect to: http://127.0.0.

1:4444/wd/hub

09:58:37.421 INFO - Version Jetty/5.1.x

09:58:37.421 INFO - Started HttpContext [/selenium-server /driver,/

selenium-server/driver]

09:58:37.437 INFO - Started HttpContext[/selenium-server,/selenium-server]

09:58:37.437 INFO - Started HttpContext[/,/]

09:58:37.531 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1503a3

09:58:37.531 INFO - Started HttpContext[/wd,/wd]

09:58:37.562 INFO - Started SocketListener on 0.0.0.0:4444

09:58:37.562 INFO - Started org.openqa.jetty.jetty.Server@1113708

在MyEclipse中对该脚本执行Run as TestNG。

执行过程将自动调用FireFox,并执行脚本动作。

.

MyEclipse执行结果如下:

相关主题