当前位置: 首页 > news >正文

加强网站集约化建设水果香精东莞网站建设技术支持

加强网站集约化建设,水果香精东莞网站建设技术支持,如何备份织梦系统做的网站,wordpress侧栏显示指定分类1.什么是selenium#xff1f; Selenium 是支持web 浏览器自动化的一系列工具和 库的综合项目。 它提供了扩展来模拟用户与浏览器的交互#xff0c;用于扩展浏览器分配的分发 服务器#xff0c; 以及用于实现W3C WebDriver 规范 的基础结构#xff0c; 该规范允许您为所有主…1.什么是selenium Selenium 是支持web 浏览器自动化的一系列工具和 库的综合项目。 它提供了扩展来模拟用户与浏览器的交互用于扩展浏览器分配的分发 服务器 以及用于实现W3C WebDriver 规范 的基础结构 该规范允许您为所有主要Web 浏览器编写可互换的代码。 Selenium 不仅仅是一个工具或 API, 它还包含许多工具. WebDriver 如果您开始使用桌面网站测试自动化, 那么您将使用 WebDriver APIs. WebDriver 使用浏览器供应商提供的浏览器自动化 API 来控制浏览器和运行测试. 这就像真正的用户正在操作浏览器一样. 由于 WebDriver 不要求使用应用程序代码编译其 API, 因此它本质上不具有侵入性. 因此, 您测试的应用程序与实时推送的应用程序相同. Selenium IDE Selenium IDE (Integrated Development Environment 集成 开发环境) 是用来开发 Selenium 测试用例的工具. 这是一个易于使用的 Chrome 和 Firefox 浏览器扩展, 通常是开发测试用例最有效率的方式. 它使用现有的 Selenium 命令记录用户在浏览器中的操作, 参数由元素的上下文确定. 这不仅节省了开发时间, 而且是学习 Selenium 脚本语法的一种很好的方法. Grid Selenium Grid允许您在不同平台的不同机器上运行测试用例. 可以本地控制测试用例的操作, 当测试用例被触发时, 它们由远端自动执行. 当开发完WebDriver测试之后, 您可能需要在多个浏览器和操作系统的组合上运行测试. 这就是 Grid 的用途所在. 2.代码工程 实验目标 打开chrome自动输入Google网页并进行搜索对搜索结果截图并保存关闭浏览器 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdspringboot-demo/artifactIdgroupIdcom.et/groupIdversion1.0-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdSelenium/artifactIdpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetselenium.version3.141.59/selenium.versionwebdrivermanager.version4.3.1/webdrivermanager.versiontestng.version7.4.0/testng.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --dependencygroupIdorg.seleniumhq.selenium/groupIdartifactIdselenium-java/artifactIdversion${selenium.version}/version/dependency!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager --!-- https://github.com/bonigarcia/webdrivermanager--dependencygroupIdio.github.bonigarcia/groupIdartifactIdwebdrivermanager/artifactIdversion${webdrivermanager.version}/version/dependency!-- https://mvnrepository.com/artifact/org.testng/testng --dependencygroupIdorg.testng/groupIdartifactIdtestng/artifactIdversion${testng.version}/versionscopetest/scope/dependency/dependencies /project 测试主类 package com.et.selenium;import com.et.selenium.page.google.GooglePage; import com.et.selenium.util.ScreenShotUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.testng.Assert; import org.testng.annotations.Test;import java.io.IOException;public class GoogleSearch1Test extends SpringBaseTestNGTest {Autowiredprivate GooglePage googlePage;Lazy // only create the object when neededAutowiredprivate ScreenShotUtil screenShotUtil;Testpublic void GoogleTest() throws IOException, InterruptedException {this.googlePage.goToGooglePage();Assert.assertTrue(this.googlePage.isAt());this.googlePage.getSearchComponent().search(spring boot);Assert.assertTrue(this.googlePage.getSearchResult().isAt());Assert.assertTrue(this.googlePage.getSearchResult().getCount() 2);System.out.println(Number of Results: this.googlePage.getSearchResult().getCount());// wait 3 secondsThread.sleep(3000);//take screenshotthis.screenShotUtil.takeScreenShot(Test.png);this.googlePage.close();} } 打开google网页 package com.et.selenium.page.google;import com.et.selenium.annotation.Page; import com.et.selenium.page.Base; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value;// this is the main page class that uses search componet and search results componet Page // using custom annotation created; src/main/java/com/demo/seleniumspring/annotation/Page.java public class GooglePage extends Base {Autowiredprivate SearchComponent searchComponent;Autowiredprivate SearchResult searchResult;Value(${application.url})private String url;//launch websitepublic void goToGooglePage(){this.driver.get(url);}public SearchComponent getSearchComponent() {return searchComponent;}public SearchResult getSearchResult() {return searchResult;}Overridepublic boolean isAt() {return this.searchComponent.isAt();}public void close(){this.driver.quit();} } 搜索“ Spring Boot”关键字 package com.et.selenium.page.google;import com.et.selenium.annotation.PageFragment; import com.et.selenium.page.Base; import org.openqa.selenium.Keys; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy;import java.util.List;PageFragment// using custom annotation created; src/main/java/com/demo/seleniumspring/annotation/PageFragment.java public class SearchComponent extends Base {FindBy(name q)private WebElement searchBox;FindBy(namebtnK)private ListWebElement searchBtns;public void search(final String keyword) {this.searchBox.sendKeys(keyword);this.searchBox.sendKeys(Keys.TAB);// CLICK first search buttonthis.searchBtns.stream().filter(e - e.isDisplayed() e.isEnabled()).findFirst().ifPresent(WebElement::click);}Overridepublic boolean isAt() {return this.wait.until(driver1 - this.searchBox.isDisplayed());} } 搜索结果截图 package com.et.selenium.util;import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import org.springframework.util.FileCopyUtils;import java.io.File; import java.io.IOException; import java.nio.file.Path;Lazy Component public class ScreenShotUtil {Autowiredprivate TakesScreenshot driver;// location of screenshot fileValue(${screenshot.path})private String path;public void takeScreenShot(final String imgName) throws IOException {// takes screenshot as saves to path in app properties file using given imgName ex. test.pngif (System.getenv(CLOUD_RUN_FLAG) null) {try {File sourceFile this.driver.getScreenshotAs(OutputType.FILE);File targetfile new File(path/imgName);FileCopyUtils.copy(sourceFile, targetfile);System.out.println(Saving screenshot to path);} catch (Exception e) {System.out.println(Something went wrong with screenshot capture e);}}} } 关闭chrome浏览器 this.googlePage.close(); 以上只是一些关键代码所有代码请参见下面代码仓 库 代码仓库 GitHub - Harries/springboot-demo: a simple springboot demo with some components for example: redis,solr,rockmq and so on.(selenium) 3.测试 启动测试方法GoogleTest效果如下面动图 4.引用 Spring Boot集成selenium实现自动化测试 | Harries Blog™Selenium
http://www.hkea.cn/news/14466859/

相关文章:

  • 化妆品网站建设建设网站的企业
  • 江阴网站制作建设网站教程
  • 网站模板下载网站有哪些品牌网站建设推广
  • 长沙公司做网站的价格做网站 空间还是服务器
  • 织梦网站做seo优化智能营销型网站制作
  • 南昌制作网站的公司做网站的行业平台
  • 河南省城乡和住房建设厅网站微信分享网站显示图片
  • 网站开发 手把手网站建设方案是什么
  • 网站 图标 素材企业网站模板下载哪家口碑好
  • 如何做旅游网站湖南建设部网站
  • wap手机网站开发软件wordpress编辑器不行
  • 苏州资讯网站建设工作态度和责任心感悟
  • 佛山优化网站公司wordpress本地打开很慢
  • 贵阳专业做网站公司有哪些广东新闻联播主持人
  • 网站如何做等保备案wordpress怎么私人媒体库
  • 做视频链接网站十大免费ppt网站软件
  • 网站怎么做动态图旅游网站设计规划书
  • wordpress仿站插件昆明购物网站建设
  • 网站有哪些布局郴州网站网络推广平台
  • 网站建设公司公司建一个公司网站多少钱
  • 网站查询ip地址查询长沙seo优化公司哪家好
  • 温州网站设计服务广东seo排名
  • 做外文网站wordpress suspected
  • 培训医院网站建设网站建设搭建环境
  • 上海做网站的公司电话wordpress 去掉左上角
  • 怎么将自己做的网站放到网上个人网站设计论文题目
  • 免费个人网站搭建完整网页开发
  • xp 做网站服务器吗wordpress数据库更改账号密码
  • 网站群 主要功能九江茶叶网站建设
  • 福州医保网站调入申报怎么做蝉知 wordpress