(三)环境安装之Selenium

虫师 创建于 almost 7 years 之前

最后更新: 2 months 之前

阅读数: 1

(三)环境安装之Selenium


通过jar包安装

点击 Selenium下载 链接 你会看到Selenium Standalone Server的介绍:

The Selenium Server is needed in order to run Remote Selenium WebDriver. Selenium 3.X is no longer capable of running Selenium RC directly, rather it does it through emulation and the WebDriverBackedSelenium interface.

Download version 3.4.0

点击版本号进行下载,下载完成将会得到一个selenium-server-standalone-3.4.0.jar文件。

或者通过 网盘下载

打开IntelliJ IDEA,导入.jar包。

点击菜单栏 File --> Project Structure(快捷键Ctrl + Alt + Shift + s) ,点击 Project Structure界面左侧 的“Modules” 。在“Dependencies” 标签界面下,点击右边绿色的“+” 号,选择第一个选项“JARs or directories...” ,选择相应的 jar 包,点“OK” ,jar包添加成功。


通过Maven安装

关于Maven安装又是另一个话题了。你可以参考其它资料学习在IntelliJ IDEA创建Maven项目。

Maven官网

idea & maven help

Maven仓库

打开pom.xml 配置Selenium。

<?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.mvn.demo</groupId>
    <artifactId>MyMvnPro</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <!-- selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.4.0</version>
        </dependency>

    </dependencies>

</project>

虽然,学习Maven需要增加你的学习成本,但如果你需要长期使用Java编程语言,或者想用Java来做更多事情的话,越早使用Maven越好!因为它会让的第三方包管理变得非常简单。


Hello Selenium

最后,少不了要写一个简单的Selenium Sample来验证Selenium安装是否成功,打开IntelliJ IDEA 创建一个新类Itest.java

package javaBase;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Itest {
    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.itest.info");

        String title = driver.getTitle();
        System.out.printf(title);

        driver.close();
    }
}

如果执行报错,请看下一节,Selenium3浏览器驱动

0

相关课程

测试工具合集
图文
测试工具合集

课程分类: 自动化测试 测试工具 中间件

我们收集的各种测试工具

  • 已完结
  • 已更新7集
  • 最后更新时间: 2024-03-18 12:04:41

免费

查看详情
selenium python 综合教程
图文
selenium python 综合教程

课程分类: 自动化测试

selenium python入门及提升

  • 已完结
  • 已更新21集
  • 最后更新时间: 2024-03-18 10:51:39

免费

查看详情
selenium javascript教程
图文
selenium javascript教程

课程分类: 自动化测试

通过selenium来入门js

  • 已完结
  • 已更新21集
  • 最后更新时间: 2024-03-18 10:29:34

免费

查看详情