• Java+seleinum+testng框架UI自动化测试环境搭建--第一节


    闲话少讲,直奔主题。

    简单的一般环境安装我就不写了,可以参考我博客其他java环境配置安装教程,IDEA安装教程。

    (一)环境安装之Java

    检查是否安装成功请在运行输入cmd,javac,java -version

    (二)环境安装之IntelliJ IDEA

    我博客其他教程有,且有破解方法。

    (三)环境安装之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();
        }
    }

    很遗憾,上面会出现一个报错信息,如下:

     解决方法在代码中加入一行驱动路径即可。

    System.setProperty("webdriver.chrome.driver", "E:\chromedriver_win32\chromedriver.exe");

     如上,我们已经打开了一个百度网页。

  • 相关阅读:
    Net Core -- 配置Kestrel端口
    NET Core迁移
    NET Core 2.0 微服务跨平台实践
    NET Core 与 Vue.js 服务端渲染
    Varnish 实战
    Hitchhiker 是一款开源的 Restful Api 测试工具
    ABP框架用Dapper实现通过SQL访问数据库
    开源框架总体介绍
    Net Core API网关Ocelot
    Jquery autocomplete插件
  • 原文地址:https://www.cnblogs.com/tiechui2015/p/12190646.html
Copyright © 2020-2023  润新知