zoukankan      html  css  js  c++  java
  • 1.selenium+java+maven+testNg 的安装

    1.搭建环境之前,要先安装java的jdk、idea工具,请自行安装

    ①Java运行环境–jdk

    https://www.oracle.com/java/technologies/javase-jdk11-downloads.html

    ②IDE–idea
    https://www.jetbrains.com/idea/download/#section=mac

    ③下载chrom对应的chromdriver,先看自己的浏览器的版本,再去下载对应的chromdriver,不然程序会报错

    https://chromedriver.storage.googleapis.com/index.html

    下载后得到的文件,在访达中打开,把下载好的文件拖动到 /usr/local/bin目录下

    打开/usr/local/bin的方法
        1 打开mac自带命令行,输入:cd /usr/local/bin
        2 再输入:open .则成功打开此目录

    这时chromdriver就配置好了,可以打开命令行输入chromedriver --version来看,能返回具体的版本号则表示安装成功~

    2.在idea里面新建一个maven项目,然后在pom.xml里面需要引入几个依赖包。

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.141.59</version>
        </dependency>
    
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>

    3. 运行一个例子

    import org.openqa.selenium.By;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    
    public class Test {
        public static void main(String[] args) {
    
            System.setProperty("webdriver.chrome.driver","/usr/local/bin/chromedriver");//这里输入chromedriver的安装目录
            ChromeDriver driver = new ChromeDriver();
            driver.get("https://www.baidu.com/");
            driver.findElement(By.name("wd")).click();
            driver.findElement(By.name("wd")).sendKeys("selenium教程" );
            driver.findElement(By.id("su")).click();
            try {
                Thread.sleep(2000);
            }catch(InterruptedException e){
                System.out.print("线程异常");
            }
            
            driver.quit();
        }
    }
  • 相关阅读:
    Win7 vs2017 WDK 1803 1809 驱动开发 出错 KMDF
    http 请求 post get 长度限制
    IO模式和IO多路复用(阻塞IO、非阻塞IO、同步IO、异步IO等概念)
    select/poll 和 epoll 比较
    centos查看端口被哪个应用端口占用命令
    mysql索引知识简单记录
    Spring钩子方法和钩子接口的使用详解
    mysql使用自增Id为什么存储比较快
    分布式Id教程
    如何配置JVM系统属性及获取方式System.getProperty("pname")
  • 原文地址:https://www.cnblogs.com/peiminer/p/13554935.html
Copyright © 2011-2022 走看看