已转开发,博客新地址:http://welcomezhang.iteye.com/

selenium入门——用selenium发新浪微博

上一篇 / 下一篇  2011-09-02 10:43:28 / 个人分类:自动化测试

作为selenium的菜鸟,闲来无事写了个selenium脚本发新浪微博和公司内网顶贴拿奖品呵,还是很有意思的。
我是用selenium RC跑case的,环境搭建就不多说了,附相关脚本。51Testing软件测试网l8jjmN3h6WR(R K

&ql;mYp0
import org.junit.*;
import static org.junit.Assert.*;
import java.util.Date;
import com.thoughtworks.selenium.*;
import java.text.SimpleDateFormat;
51Testing软件测试网0c y.~3aJ`zb%o
//小匡的应用:学以致用哇
public class TestByKuang extends Search {

'rFAcd v Sh4y0
    public static Selenium localSelenium;

)G `:{ f:eu0`0
    @Before
    public void    init() {
        localSelenium = selenium;
    }

W r'B:MZN,@0
//小匡应用1:测试selenium添加新浪微博
    @Test
    public void testAddWeibo(){
    open("http://weibo.com/");
    //登录,微博密码保密哦
    String xpath = "//input[@id='loginname']";
    selenium.type(xpath, "********@126.com");  
    xpath = "//input[@id='password']";
    selenium.type(xpath, "************");
    xpath="//a[@id='login_submit_btn']";
    selenium.click(xpath);
    Util.mySleep(5000);
    
    xpath = "//div[@class='inputarea']/textarea[@id='publish_editor']";
    Date now = new Date();
    SimpleDateFormat sdf = new  SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
    selenium.type(xpath, "Test自动发布新浪微博by selenium @ "+sdf.format(now));
    Util.mySleep(5000);
    xpath="//div[@class='connBg']/div/a[@id='publisher_submit']";
    selenium.click(xpath);
    Util.mySleep(5000);
}
}

TAG: Selenium selenium 自动化

 

评分:0

我来说两句

Open Toolbar