自动化测试1_java+appium初探

摘要:
第一个自动化的例子  首先创建了java的项目、包、类之后,右键项目名称,点击properties,选择javabuildpath,把selenium添加到项目里面。从selenium的官网中复制下来一个例子,跑一边简单的流程。大体的代码如下,我把官网的代码稍微修改了一下,然后做了简单的注释。

第一个自动化的例子  

首先创建了java的项目、包、类之后,右键项目名称,点击properties,选择java build path,把selenium添加到项目里面。

从selenium的官网中复制下来一个例子,跑一边简单的流程。大体的代码如下,我把官网的代码稍微修改了一下,然后做了简单的注释。

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.chrome.ChromeDriver;
public classFirstAuto {
    public static voidmain(String[] args){
                //设置driver路径
                System.setProperty("webdriver.chrome.driver", "E:\chromedriver.exe");
                //打开浏览器
                WebDriver driver = newChromeDriver();


                //打开网址
                driver.get("http://www.baidu.com");

                //ͨ定位到输入框
                WebElement element = driver.findElement(By.name("wd"));

                //输入框
                element.sendKeys("测试!");

                //提交搜索
element.submit();

                //获取网站的标题,然后打印出来
                System.out.println("Page title is: " +driver.getTitle());
                
                //校验标题
                System.out.println("Page title is: " +driver.getTitle());
//加个等待,然后关闭浏览器
try{ Thread.sleep(10000); } catch(InterruptedException e) { //TODO Auto-generated catch block e.printStackTrace(); } //Close the browser driver.quit(); } }

免责声明:文章转载自《自动化测试1_java+appium初探》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇RDLC报表改动的注意事项之增加字段和参数PLSQL中查询数据的时候查询结果显示中文乱码(转)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Selenium-Switch--切换浏览器tab/iframe/alart

Switch 我们在UI自动化测试时,总会出现新建一个tab页面、弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了。需要用到Selenium单独提供的模块switch_to模块 引用路径 # 第一种方式可以通过直接导入SwitchTo模块来进行操作 from selenium.webd...

使用selenium模拟登陆12306以及滑块验证

selenium是一个自动化测试工具,利用它可以驱动浏览器执行特定的动作,如点击,下拉等操作,同时还可以获取浏览器当前呈现的页面源码,做到可见即可爬。常常被运用于爬取javascript动态渲染的页面。 下面是其简单用法: 通过浏览器发起请求获取响应页面源码数据然后利用xpath进行数据提取 fromselenium import webdriver fr...

Selenium Webdirver API(1)

Selenium Webdirver API 前提:引入webdriver包 from selenium import webdriver 1、创建浏览器对象driver = webdriver.Ie(executable_path="D:\IEDriverServer")#不同浏览器只需更改浏览器名称即可,如:webdriver.Chrome() web...

用selenium 自动爬取某一本小说章节及其内容,并存入数据库中

1 from selenium import webdriver 2 import pymysql 3 from selenium.webdriver.support.ui import WebDriverWait # 等待 4 from selenium.webdriver.support import expected_conditi...

弹窗操作

一.弹窗的三种类型 HTML代码如下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title><...

Selenium 实现鼠标悬浮

http://blog.csdn.net/huilan_same/article/details/52305176 #ActionChains基本用法 from selenium import webdriver from selenium.webdriver.common.action_chains import * import time dri...