关闭

编写自动化测试代码—Selenium自动化测试指南(11)

发表于:2013-9-09 11:19

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:赵卓    来源:51Testing软件测试网

  程序清单7-8  Selenium 1 C#代码

package Project1;
import com.thoughtworks.selenium.*; //注意这里导入了selenium包中的内容
public class Project1Class {
public static void main(String[] args) throws InterruptedException {
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore", http://www.google.com);
selenium.start();
//第1步
selenium.open(http://www.360buy.com/);
System.out.println("检查是否成功进入京东首页:" + "http://www. 360buy.com/". equals (selenium.getLocation()));
//第2步
selenium.type("id=key", "sdfgasfdgdsfgdsfgdsfg");
selenium.click("//input[@value='搜索']");
selenium.waitForPageToLoad("30000");
System.out.println("页面上出现“抱歉,没有找到与‘sdfgasfdgdsfgdsfgdsfg’相关的商品。”等字样:" + selenium.isTextPresent("抱歉,没有找到与“sdfgasfdgdsfgdsfgdsfg”相关的商品"));
//第3步
selenium.type("id=key", "收集");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("页面上出现“您要找的是不是:手机”:" + "您要找的是不是:手机".equals (selenium.getText("id=correctbox")));
//第4步
selenium.type("id=key", "团购");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("进入京东团购页面,URL中包含“http://tuan.360buy.com/”:" + "http: //tuan.360buy.com/chengdu-0-0-0-0-0-0-1-0-0.html".equals(selenium.getLocation()));
//第5步
selenium.goBack();
Thread.sleep(2000);
selenium.type("id=key", "移动");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("在搜索页面中出现“手机充值”等相关控件:" + selenium. IsElementPresent ("//input[@value='立即充值']"));
//第6步
selenium.type("id=key", "图书");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("搜索出来的结果将以列表的形式显示:" + "m psearch plist-book".equals (selenium.getAttribute("//div[@id='plist']/@class")));
//第7步
selenium.type("id=key", "手机");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("搜索出来的结果将以网格的形式显示:" + "m psearch ".equals(selenium. getAttribute("//div[@id='plist']/@class")));
//第8步
selenium.type("id=key", "635085");
selenium.click("//input[@value='搜索']");
Thread.sleep(5000);
System.out.println("进入该商品的具体信息页面,URL中包含“http:// www.360buy. com/ product/”:" + "http://www.360buy.com/product/635085.html".equals(selenium.getLocation()));
selenium.stop();
}
}

本文选自《Selenium自动化测试指南》第五章节,本站经人民邮电出版社和作者的授权,近期将进行部分章节的连载,敬请期待!

版权声明:51Testing软件测试网获人民邮电出版社和作者授权连载本书部分章节。

任何个人或单位未获得明确的书面许可,不得对本文内容复制、转载或进行镜像,否则将追究法律责任。

相关文章:

自动化测试的实施—Selenium自动化测试指南(10)

购买商品功能的测试代码—Selenium自动化测试指南(12)

55/5<12345
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • cxwtomcat
    2014-6-08 10:51:34

    这里看看就行了,书嘛凑字数太严重了,鄙视作者出版社和51testing

  • zm51testing
    2013-9-13 15:22:27

    不好意思哈!老师:您的《编写自动化测试代码—Selenium自动化测试指南(11)》第五页的【程序清单7-8  Selenium 1 C#代码】是不是应该改写成【程序清单7-8  Selenium 1 java代码】

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号