selenium+maven+idea打开百度样例

记得刚毕业的时候, 这个简单的案例,捣鼓了一个星期,因为当时项目经理想让我转自动化测试。但当时基础渣渣。 现在怀念起来,也就是半个小时,搭建好。然后写好说明文档。经验和处理问题的能力还是必须的。

一个通过selenium+maven+idea打开百度 实现自动打开火狐浏览器 百度网站的小例子 其中已经包含了 需要添加 打开火狐浏览器的驱动程序

搭建:
项目架构:
这里写图片描述

搭建步骤:
这里写图片描述
1、创建名字为seleniumHelloworld 的maven 工程
2、添加pom.xml文件(jar包依赖)
3、写个打开测试用例
4、复制火狐的驱动程序geckodriver.exe 到 D:\firefoxDriver\geckodriver.exe

项目下载路径:
https://download.csdn.net/download/u010050174/10558171
这里写图片描述

以下为具体的代码:也可以直接下载项目 运行 有问题 文章末尾评论
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>seleniumHelloworld</groupId>
    <artifactId>seleniumHelloworld</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.25.0</version>
        </dependency>

        <!--testng 依赖-->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

OpenBaidu.java

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenBaidu {
    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver", "D:\\firefoxDriver\\geckodriver.exe");
        WebDriver driver = null;
        driver = new FirefoxDriver();
        driver.get("http://www.baidu.com");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值