• 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();
        }
    }
  • 相关阅读:
    DotnetCore 使用Jwks验证JwtToken签名
    HashCode
    C# RedisRateLimiter
    Centos7 使用Dockerfile 制作自己的Dotnetcore程序镜像
    ES6 HttpApplication Middleware
    请转发!简单2分钟制作无接触式小区进出微信登记表!全免费!数据安全!所有数据均存在创建人登录的QQ腾讯文档里!
    理解虚基类、虚函数与纯虚函数的概念
    不无道理
    乔布斯:不要为明天忧虑!
    【心态不好,人生易老】
  • 原文地址:https://www.cnblogs.com/peiminer/p/13554935.html
Copyright © 2020-2023  润新知