Java+maven+selenium3+testng 自动化测试环境IDEA

idea 、java环境变量jdk maven安装及环境变量配置这里就不多说了,网上有很多教程

这里我们只检测一下java、maven环境是否安装成功

win+R,运行cmd命令行:mvn -v 检查maven是否安装成功,如下图即成功!

Java+maven+selenium3+testng 自动化测试环境IDEA_第1张图片
java -v 检查java版本 javac 环境是否安装成功,如下图即成功!

二、配置Maven Repository

1.配置本地仓库,maven会从中间仓库下载需要的jar包到本地,我们可以修改存放的位置,在maven安装目录的conf文件夹下的setting.xml文件。如下图的位置,修改即可,路径随意改成你想要的位置就好
Java+maven+selenium3+testng 自动化测试环境IDEA_第2张图片
2.配置中间仓库,这里提供了国内的阿里云镜像,同样在setting.xml中修改,查找mirrors,在…之间

Java+maven+selenium3+testng 自动化测试环境IDEA_第3张图片

三、搭建Maven项目

搭建步骤

1、打开IDEA,新建一个maven项目,New-> project->maven

2、在Maven库中查找所需jar包,selenium-java,testng等,获取相应的maven库获取dependency。maven库连接:http://mvnrepository.com/search?q=selenium

Java+maven+selenium3+testng 自动化测试环境IDEA_第4张图片
3、打开maven项目中的pom.xml文件,配置dependencies

Java+maven+selenium3+testng 自动化测试环境IDEA_第5张图片
4、点击文件右击选择maven->reimport,这样就获取了所有所需jar包。

5、然后开始第一个selenium测试,selenium3.0之后都需要到selenium官网下载相应的浏览器驱动:http://www.seleniumhq.org/download/

若不能打开selenium官网,请到百度要下载的驱动。(一个驱动参考博客:http://www.cnblogs.com/iceb/p/7195876.html Chrome 驱动:http://chromedriver.storage.googleapis.com/index.html )

  1. 然后把下载好的驱动放到系统环境变量Path中的路径下,例如:C:\Windows\System32 这里也可以自己配置驱动路径

7.新建一个test ,试试是否成功打开浏览器运行,

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
public class test {
    @BeforeClass
    public void beforeClass(){
        System.out.println("用例执行前打印改语句");
        System.out.println("每条Test用例是互不相干的");
        System.out.println("用例开始执行…………");
    }
    @AfterClass
    public void afterClass(){
        System.out.println("用例结束后运行");
    }
    @Test
    public static void main(String[] args) {
        WebDriver dr;
        dr=new ChromeDriver();
        dr.get("https://www.baidu.com");
        dr.quit();

    }
//    public void actions(){
//        //设置驱动所在位置
//        System.setProperty("webdriver.chrome.driver", "D:\\Software\\Python37\\Scripts\\chromedriver.exe");
//        //引用火狐浏览器驱动
//        WebDriver driver = new ChromeDriver();
//        //打开百度界面
//        driver.get("https://www.baidu.com");
//        try {
//            //页面等待
//            Thread.sleep(300);
//            driver.quit();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        }
}

运行后

D:\Software\Java\jdk1.8.0_172\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA 2018.1.6\lib\idea_rt.jar=12819:D:\Software\IntelliJ IDEA 2018.1.6\bin" -Dfile.encoding=UTF-8 -classpath D:\Software\Java\jdk1.8.0_172\jre\lib\charsets.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\deploy.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\access-bridge-64.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\cldrdata.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\dnsns.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\jaccess.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\jfxrt.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\localedata.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\nashorn.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\sunec.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\sunjce_provider.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\sunmscapi.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\sunpkcs11.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\ext\zipfs.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\javaws.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\jce.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\jfr.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\jfxswt.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\jsse.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\management-agent.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\plugin.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\resources.jar;D:\Software\Java\jdk1.8.0_172\jre\lib\rt.jar;D:\Software\Project_Java\java_selenium_testng\target\test-classes;D:\Software\Project_Java\java_selenium_testng\target\classes;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-java\3.255 173)">14.0\selenium-java-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-api\3.255 173)">14.0\selenium-api-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.255 173)">14.0\selenium-chrome-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.255 173)">14.0\selenium-edge-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.255 173)">14.0\selenium-firefox-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.255 173)">14.0\selenium-ie-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.255 173)">14.0\selenium-opera-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.255 173)">14.0\selenium-remote-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.255 173)">14.0\selenium-safari-driver-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\seleniumhq\selenium\selenium-support\3.255 173)">14.0\selenium-support-3.255 173)">14.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\net\bytebuddy\byte-buddy\1.8.255 173)">15\byte-buddy-1.8.255 173)">15.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;D:\Software\Java\apache-maven-3.5.2\repository\commons-codec\commons-codec\1.255 173)">144 255 173)">10\commons-codec-1.255 173)">144 255 173)">10.jar;D:\Software\Java\apache-maven-3.5.2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\google\guava\guava\25.0-jre\guava-25.0-jre.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\checkerframework\checker-compat-qual\2.0.0\checker-compat-qual-2.0.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\google\errorprone\error_prone_annotations\2.1.3\error_prone_annotations-2.1.3.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\codehaus\mojo\animal-sniffer-annotations\1.255 173)">14\animal-sniffer-annotations-1.255 173)">14.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\apache\httpcomponents\httpclient\4.5.5\httpclient-4.5.5.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\apache\httpcomponents\httpcore\4.4.9\httpcore-4.4.9.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\squareup\okhttp3\okhttp\3.255 173)">144 255 173)">10.0\okhttp-3.255 173)">144 255 173)">10.0.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\squareup\okio\okio\1.255 173)">14.1\okio-1.255 173)">14.1.jar;D:\Software\Java\apache-maven-3.5.2\repository\org\testng\testng\7.0.0-beta1\testng-7.0.0-beta1.jar;D:\Software\Java\apache-maven-3.5.2\repository\com\beust\jcommander\1.72\jcommander-1.72.jar test
Starting ChromeDriver 2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e) on port 31242
Only local connections are allowed.
十一月 08, 2018 3:28:20 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: OSS

Process finished with exit code 0

成功运行,然后开始框架目录的搭建,后续在写

最后:下方这份完整的软件测试视频学习教程已经整理上传完成,朋友们如果需要可以自行免费领取 【保证100%免费】

在这里插入图片描述

你可能感兴趣的:(java,intellij-idea,maven,自动化测试,软件测试)