IDEA+TestNG+MAVEN实践(2)——PC端WEB操作

分析:PC端WEB操作,需要使用到selenium,以及相关浏览器的驱动。

一、添加selenium资源依赖

1、搜索查询到selenium-java的MAVEN引用依赖

https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-javahttps://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java

 

 2、复制maven引用依赖到pom.xml文件

 二、导入驱动

1、查询需要的驱动(此处以Chrome浏览器为例)

1)查找对应浏览器版本号(帮助>关于)

2)找到并下载对应驱动

ChromeDriver Mirrorhttp://npm.taobao.org/mirrors/chromedriver/

 3)将驱动放入项目资源目录下

三、新增测试类

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class openWEB {

    @Test
    public void login() throws IOException, InterruptedException {
        System.setProperty("webdriver.chrome.driver", "F:\\testNG_WorkSpace\\src\\main\\resources\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("http://www.baidu.com");
        Thread.sleep(3000);
        driver.quit();
//      Runtime.getRuntime().exec("TASKKILL /F /IM  chromedriver.exe");
    }
}

四、将测试类加入testng.xml中 

五、执行测试类/testng.xml

OK!执行完成。 


版权声明:本文为cat5cat6原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。