zoukankan      html  css  js  c++  java
  • 基于jdk8+selenium3+chrome86的UI自动化测试

    创建一个maven工程

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.zawx</groupId>
        <artifactId>yaqgj_zawx_test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
    
    
        <dependencies>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.14.3</version>
            </dependency>
    
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.141.59</version>
            </dependency>
    
        </dependencies>
    
    </project>
    View Code

    验证chromedriver测试开发环境

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.testng.Assert;
    
    class  TestBaidu0325 {
        public static void main(String[] args) {
            /*google浏览器*/
            //找不到chromedriver时,强制制定webdriver路径。
            System.setProperty("webdriver.chrome.driver","D:\javaweb\selenium\chromedriver.exe");
    
            WebDriver driver =new ChromeDriver();
    
            String url = "http://www.baidu.com";
    
            driver.get(url);
    
            driver.manage().window().maximize();//窗口最大化,加大页面回访的稳定性
    
            driver.findElement(By.id("kw")).sendKeys("selenium");
    
            driver.findElement(By.id("su")). click ();
    
            try {
    
                Thread.sleep(1000);//延时设置,避免网页加载慢找不到页面元素
    
            } catch (InterruptedException e) {
    
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
            /*所谓的断言*/
            Assert.assertTrue(driver.getTitle().contains("selenium"));
            driver.quit();
        }
    }
    部分内容来自于学习编程期间收集于网络的免费分享资源和工作后购买的付费内容。
  • 相关阅读:
    Docker 部署 ElasticSearch-Head
    linux安装kibana-7.6.1
    CentOS部署ElasticSearch7.6.1集群
    linux 安装mysql 8
    Docker安装Mysql,并搭建一主一从复制集群,一主双从,双主双从集群
    linux 挂载光盘,rmp,yum
    git多账号登录问题
    js动态添加事件-事件委托
    yii2 RESTful api的详细使用
    yii2 ActiveRecord多表关联以及多表关联搜索的实现
  • 原文地址:https://www.cnblogs.com/MarlonKang/p/14472919.html
Copyright © 2011-2022 走看看