梅州站改造高铁站,重庆seo1,官方网站开发商,网站如何做监测链接1.自动化测试分类 接口自动化测试UI自动化测试#xff08;移动端自动化测试、Web端自动化测试#xff09; 2.选择Selenium作为web自动化工具原因#xff08;面试题#xff09; 开源免费支持多个浏览器支持多个系统支持多语言Selenium包提供很多供测试使用的API 3.自动化是什…1.自动化测试分类 接口自动化测试UI自动化测试移动端自动化测试、Web端自动化测试 2.选择Selenium作为web自动化工具原因面试题 开源免费支持多个浏览器支持多个系统支持多语言Selenium包提供很多供测试使用的API 3.自动化是什么为什么要做自动化  自动化是测试人员为了提高效率或者保证测试质量减少人力消耗让代码辅助测试人员来执行测试的一个过程 4.自动化脚本打开浏览器的工作原理 编写的自动化脚本----创建http请求发送给浏览器驱动----浏览器驱动包含一个http server请求---操控浏览器----执行测试步骤驱动作用驱动接收自动化脚本发送过来的http请求并解析请求发送给浏览器当浏览器执行完成后会把结果返回给脚本 5. 使用Java编写Selenium编写的自动化脚本的步骤 创建maven项目在pom.xml里将依赖导入 dependenciesdependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion4.0.0/version/dependency
/dependencies 开始进行自动化脚本的编写  public void dilireba(){//创建驱动对象ChromeOptions optionsnew ChromeOptions();options.addArguments(--remote-allow-origins*);ChromeDriver drivernew ChromeDriver(options);//访问网络driver.get(http://baidu.com);//查找元素并且操作元素driver.findElement(By.cssSelector(#kw)).sendKeys(迪丽热巴);driver.findElement(By.cssSelector(#su)).click();//结束会话driver.quit();} 6.查找元素  findElement     查找当前的一个元素 ,返回值为WebElement driver.findElement(By.cssSelector(#kw)) findElenments()      查找当前相同多个元素, 返回值为ListWebElement ListWebElement elesdriver.findElements(By.className(hotsearch-item));//打印每个名称for (WebElement els: eles ) {System.out.println(els.getText());} 7.元素定位 自动化要求元素定位必须唯一 选择器Selector 选择页面指定元素 driver.findElement(By.cssSelector(#kw)) Xpath driver.findElement(By.xpath(//*[idkw]))8.常见元素操作  输入文本 sendkeys,仅使用于文字字段 driver.findElement(By.cssSelector(#kw)).sendKeys(小嘉); 点击 click  driver.findElement(By.cssSelector(#su)).click(); 提交  submit,仅适用于表单元素 driver.findElement(By.cssSelector(#su)).submit(); 获取文本  getText()打印这个属性的值 String retdriver.findElement(By.className(title-content-title)).getText();System.out.println(ret); 清除 clear 测试是否可以频繁输入 driver.findElement(By.cssSelector(#su)).clear(); 获取标题 getTitle()  System.out.println(driver.getTitle()); 获取url  geturl()  System.out.println(driver.getCurrentUrl());    获取属性的值  getAttribute() System.out.println(driver.findElement(By.cssSelector(#su)).getAttribute(value)); 9.窗口设置 窗口最大化 //窗口最大化driver.manage().window().maximize(); 窗口最小化  //窗口最小driver.manage().window().minimize(); 窗口全屏   driver.manage().window().fullscreen(); 手动设置窗口大小 //手动设置driver.manage().window().setSize(new Dimension(1024,4444)); 窗口切换浏览器每次打开一个标签页就会自动给每个标签页有一个标识叫做句柄10  //输入网址driver.get(http://baidu.com);//点击更多标签页driver.findElement(By.cssSelector(#s-top-left  div  a)).click();//先获取所有标签的句柄SetStringhandles driver.getWindowHandles();//获取当前页面句柄String curhandledriver.getWindowHandle();System.out.println(当前页面句柄curhandle);//获取所有的句柄for (String handle: handles) {if (handle!curhandle){//进行页面切换driver.switchTo().window(handle);}}//查找更多页面的某个元素Thread.sleep(2000);driver.findElement(By.cssSelector(#content  div:nth-child(2)  div:nth-child(2)  a));Thread.sleep(2000);driver.quit(); 10.屏幕截图  在pom.xml里面导入依赖 dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.6/version/dependency 进行截图 public void test1() throws IOException {//启动驱动ChromeOptions optionsnew ChromeOptions();options.addArguments(--remote-allow-origins*);ChromeDriver drivernew ChromeDriver(options);//输入网址driver.get(http:baidu.com);//找到输入框去输入元素driver.findElement(By.cssSelector(#kw)).sendKeys(迪丽热巴);//屏幕截图以文件形式File srcfiledriver.getScreenshotAs(OutputType.FILE);//把它放在指定路径String filenamemy.png;FileUtils.copyFile(srcfile,new File(filename));driver.quit();} 11.等待  强制等待Thread.sleep(时间)隐式等待作用于driver的整个生命周期会一直轮寻判断元素是否存在如果不存在就等待设置好的时间里不断进行轮询等到元素全被访问 public void test2(){//启动驱动ChromeOptions optionsnew ChromeOptions();options.addArguments(--remote-allow-origins*);ChromeDriver drivernew ChromeDriver(options);//开始隐式等待driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));//输入网址driver.get(http:baidu.com);//找到输入框去输入元素driver.findElement(By.cssSelector(#kw)).sendKeys(迪丽热巴);driver.quit();} 显示等待 针对代码一条去设置  new WebDriverWait(driver,Duration.ofSeconds(间)).until(driver.findElement(By.cssSelector())); 12.浏览器导航  //后退回之前状态driver.navigate().back();//前进driver.navigate().forward();//刷新driver.navigate().refresh(); 13.弹窗  将driver对象作用到弹窗上切换弹窗 driver.switchTo.alert()确认--accept    取消---dismiss    输入文本----sendkeys警告弹窗--只有1个按钮     确认弹窗--可以选择确定和取消    提示弹窗--可以输入文本 14.选择框 可以根据文本选择、根据属性值选择、根据文本选择 
void selectControll() throws InterruptedException {
//        driver.get(file:///D:/file/%E6%AF%94%E7%89%B9%E6%95%99%E5%8A%A1/%E6%B5%8B%E8%AF%95/selenium4html/selenium-html/select.html);
//        Thread.sleep(3000);
//         WebElement ele  driver.findElement(By.cssSelector(#ShippingMethod));
//        //先创建选择框对象
//        Select select  new Select(ele);
//        Thread.sleep(3000);
//        //根据文本来选择select.selectByVisibleText(UPS Next Day Air  $12.51);
//        //根据属性值来选择select.selectByValue(12.51);
//        //根据序号来选择
//        select.selectByIndex(1);   序号从0开始
//        Thread.sleep(3000);
//        driver.quit();
//    } 
15.执行脚本 executeScriptjs代码 
void scriptControll() throws InterruptedException {driver.get(https://baidu.com/);Thread.sleep(3000);//执行js命令:让页面置顶/置底//如果想要滑到最小面值设置的大一些就行         driver.executeScript(document.documentElement.scrollTop500);Thread.sleep(3000);//0就是顶部driver.executeScript(document.documentElement.scrollTop0);driver.get(https://www.baidu.com);Thread.sleep(3000);driver.executeScript(var texts  document.querySelector(#kw);texts.value1111);Thread.sleep(3000);driver.quit();} 
16.文件上传 
void fileUploadControll() throws InterruptedException {      driver.get(url的路径);
Thread.sleep(3000);driver.findElement(By.cssSelector(body  div  div  input[typefile])).sendKeys(D:\\file\\比特教务\\测试\\selenium4html\\selenium-html\\upload.html);
//写入上传文件的文件夹路径和文件名Thread.sleep(3000);driver.quit(); 
17.浏览器参数的设置需要在创建对象之前设置 测试人员只会查看结果不关注过程所以需要设置无头模式自动执行我们在界面上看不到的我们只可以在终端看见效果       void paramsControll(){//百度搜索迪丽热巴//先创建选项对象然后再设置浏览器参数ChromeOptions options  new ChromeOptions();options.addArguments(-headless);ChromeDriver driver  new ChromeDriver(options);driver.get(https://www.baidu.com);driver.findElement(By.cssSelector(#kw)).sendKeys(迪丽热巴);driver.findElement(By.cssSelector(#su)).click();driver.quit(); 
 文章转载自: http://www.morning.dqzcf.cn.gov.cn.dqzcf.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.qkkmd.cn.gov.cn.qkkmd.cn http://www.morning.kpbgp.cn.gov.cn.kpbgp.cn http://www.morning.wjdgx.cn.gov.cn.wjdgx.cn http://www.morning.fdmtr.cn.gov.cn.fdmtr.cn http://www.morning.dwxqf.cn.gov.cn.dwxqf.cn http://www.morning.myxps.cn.gov.cn.myxps.cn http://www.morning.smygl.cn.gov.cn.smygl.cn http://www.morning.21r000.cn.gov.cn.21r000.cn http://www.morning.pqchr.cn.gov.cn.pqchr.cn http://www.morning.dtmjn.cn.gov.cn.dtmjn.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.xwlmr.cn.gov.cn.xwlmr.cn http://www.morning.nlpbh.cn.gov.cn.nlpbh.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.bgrsr.cn.gov.cn.bgrsr.cn http://www.morning.dkzrs.cn.gov.cn.dkzrs.cn http://www.morning.wcgfy.cn.gov.cn.wcgfy.cn http://www.morning.pjrql.cn.gov.cn.pjrql.cn http://www.morning.ckfyp.cn.gov.cn.ckfyp.cn http://www.morning.znsyn.cn.gov.cn.znsyn.cn http://www.morning.gbcnz.cn.gov.cn.gbcnz.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.zhqfn.cn.gov.cn.zhqfn.cn http://www.morning.lkgqb.cn.gov.cn.lkgqb.cn http://www.morning.trjr.cn.gov.cn.trjr.cn http://www.morning.brhxd.cn.gov.cn.brhxd.cn http://www.morning.sjqml.cn.gov.cn.sjqml.cn http://www.morning.qmsbr.cn.gov.cn.qmsbr.cn http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.qnzld.cn.gov.cn.qnzld.cn http://www.morning.jtdrz.cn.gov.cn.jtdrz.cn http://www.morning.yksf.cn.gov.cn.yksf.cn http://www.morning.hmtft.cn.gov.cn.hmtft.cn http://www.morning.jbblf.cn.gov.cn.jbblf.cn http://www.morning.pumali.com.gov.cn.pumali.com http://www.morning.thpzn.cn.gov.cn.thpzn.cn http://www.morning.yymlk.cn.gov.cn.yymlk.cn http://www.morning.nhzps.cn.gov.cn.nhzps.cn http://www.morning.tdhxp.cn.gov.cn.tdhxp.cn http://www.morning.wwkdh.cn.gov.cn.wwkdh.cn http://www.morning.wnbpm.cn.gov.cn.wnbpm.cn http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn http://www.morning.nngq.cn.gov.cn.nngq.cn http://www.morning.zsyrk.cn.gov.cn.zsyrk.cn http://www.morning.sfcfy.cn.gov.cn.sfcfy.cn http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.yrxcn.cn.gov.cn.yrxcn.cn http://www.morning.rjqtq.cn.gov.cn.rjqtq.cn http://www.morning.thrcj.cn.gov.cn.thrcj.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.pwdrc.cn.gov.cn.pwdrc.cn http://www.morning.hdtcj.cn.gov.cn.hdtcj.cn http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn http://www.morning.qgmwt.cn.gov.cn.qgmwt.cn http://www.morning.rnrwq.cn.gov.cn.rnrwq.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.lmxzw.cn.gov.cn.lmxzw.cn http://www.morning.wbfg.cn.gov.cn.wbfg.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.dtgjt.cn.gov.cn.dtgjt.cn http://www.morning.mbfj.cn.gov.cn.mbfj.cn http://www.morning.fdzzh.cn.gov.cn.fdzzh.cn http://www.morning.xsymm.cn.gov.cn.xsymm.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.iznek.com.gov.cn.iznek.com http://www.morning.ygmw.cn.gov.cn.ygmw.cn http://www.morning.qwdlj.cn.gov.cn.qwdlj.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn