如何利用Selenium IDE 生成可参考的java代码

1. Install Selenium IDE as a plugin of firefox browser.  You'd better download the latest one from http://seleniumhq.org/download/

 

 

2. Create a java file "fromide.java" in your eclipse project as below structure.  This file should be empty at this time.

 

 
 

3. Start it to record a script about any operation.

 

4. Save it to fromide.java in your eclipse project as Junit4 code.  Cover the existing one.

 

 

5. Open it in Eclipse.  Remember it's unavailable now.

 

 

6. Define selenium variable as below.  In order to make it available.

 package com.example.tests;

import com.thoughtworks.selenium.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class fromide {
 private DefaultSelenium selenium; // Notice: This line should be added manually.

 @Before
 public void setUp() throws Exception {
  selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.baidu.com/");
  selenium.start();
 }

 @Test
 public void testFromide() throws Exception {
  selenium.open("/");
  selenium.type("id=kw", "asd");
  selenium.type("id=kw", "selenium webdriver");
  selenium.waitForPageToLoad("30000");
  selenium.click("//table[@id='1']/tbody/tr/td/h3/a/font[2]");
 }

 @After
 public void tearDown() throws Exception {
  selenium.stop();
 }
}

7. Run it.  It would simulate your operation per Eclipse.  That's what we need.  Then we can modify and utilize it in Eclipse.  It's a professional way to develop selenium Java code.  Record the code by Selenium IDE first, then develop it in Eclipse to make it more comfortable as you want.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值