• Java+Selenium+Junit实现web自动化demo


    1.新建maven工程

    打开IDEA新建maven项目并引入相关依赖,步骤如下:

    需要引入的依赖

    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.codehaus.jettison</groupId>
          <artifactId>jettison</artifactId>
          <version>1.3.7</version>
        </dependency>
        <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <version>6.14.3</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>3.141.59</version>
        </dependency>
        <dependency>
          <groupId>io.appium</groupId>
          <artifactId>java-client</artifactId>
          <version>7.0.0</version>
        </dependency>
      </dependencies>

    2.编写代码

    代码如下:

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class TestBaidu {
        private WebDriver driver;
    
        @Before
        public void setUp() throws Exception {
            //System.setProperty("webdriver.chrome.driver", "/Users/ceshi/Driver/chromedriver");
            driver = new ChromeDriver();
        }
    
        @Test
        public void openEditor() throws InterruptedException {
            driver.get("https://www.baidu.com");
            Thread.sleep(3000);
            driver.findElement(By.id("kw")).sendKeys("菜鸟教程");
            Thread.sleep(2000);
            driver.findElement(By.id("su")).click();
        }
    
        @After
        public void tearDown() throws Exception {
            driver.close();
        }
    }
  • 相关阅读:
    2019-9-2-正则表达式30分钟入门教程
    2019-6-23-开源项目使用-appveyor-自动构建
    2019-8-29-dotnet-core-使用-sqlite-部署到-Centos-服务器
    2018-10-19-Roslyn-使用-Directory.Build.props-文件定义编译
    2019-4-29-dotnet-通过-WMI-获取系统安装软件
    2018-12-24-win10-uwp-求两个矩形相连的几何
    shell公共函数functions
    linux防火墙和SELinux
    ubuntu开启ssh
    文件夹操作
  • 原文地址:https://www.cnblogs.com/wanyuan/p/16408758.html
Copyright © 2020-2023  润新知