首页 > 编程语言 > 详细

1.selenium+java+maven+testNg 的安装

时间:2020-08-24 18:39:02      阅读:60      评论:0      收藏:0      [点我收藏+]

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();
    }
}

 

1.selenium+java+maven+testNg 的安装

原文:https://www.cnblogs.com/peiminer/p/13554935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!