zoukankan      html  css  js  c++  java
  • TestNG+Java+Selenium+Maven 代码实例

    搭环境时注意不要忘记testng的jar包,selenium的jar包

    package com.guge.test;

    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;

    import java.util.Scanner;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.Assert;
    import org.testng.annotations.AfterMethod;

    public class Guge {
    WebDriver driver=new FirefoxDriver();

    @Test
    public void login() throws InterruptedException {
    //driver.get("http://guge.user.yunpaas.cn/gugeUser/index.html#/home");
    driver.manage().window().maximize();//窗口最大化

    driver.get("http://www.baidu.com/");

    //账号密码,获取验证码
    driver.findElement(By.xpath(".//*[@id='app']/div/div[1]/form/div[1]/div/div[1]/input")).sendKeys("13284079862");
    driver.findElement(By.xpath(".//*[@id='app']/div/div[1]/form/div[2]/div/div/input")).sendKeys("123456");
    driver.findElement(By.className("getcode")).click();

    //控制台输入验证码
    Scanner sc = new Scanner(System.in);
    System.out.println("请输入6位数字验证码:(按回车键继续)");
    String code = sc.nextLine();

    driver.findElement(By.xpath(".//*[@id='app']/div/div[1]/form/div[3]/div/div/input")).sendKeys(code); //控制台的验证码填写在输入框里
    driver.findElement(By.className("login_from_btn")).click();
    System.out.println("登录中...");

    //断言
    Thread.sleep(8000);
    Assert.assertEquals(driver.findElement(By.xpath(".//*[@id='app']/div/div[2]/div/div/div[1]/div[1]/div/span[1]")).getText(),"欢迎 !","登录失败!"); //实际值,预期值,提示信息
    System.out.println("登录成功......");
    }

    @Test
    public void denglubtn(){
    Assert.assertEquals(driver.findElement(By.xpath(".//*[@id='app']/div/div[2]/div/div/div[1]/div[1]/div/span[2]")).getText(),"北京聚通达科技股份有限公司(勿删)","公司名称错误!");
    //driver.findElement(By.xpath(".//*[@id='app']/div/div[1]/div[1]/ul/li[1]/span")).click();
    //driver.findElement(By.xpath(".//*[@id='app']/div/div[2]/div/div/div[2]/div/div[1]/div[1]/div[2]")).click();
    }

    @BeforeMethod
    public void beforeMethod() {
    }

    @AfterMethod
    public void afterMethod() {
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
    }
    }

  • 相关阅读:
    HDU 5912 Fraction (模拟)
    CodeForces 722C Destroying Array (并查集)
    CodeForces 722B Verse Pattern (水题)
    CodeForces 722A Broken Clock (水题)
    CodeForces 723D Lakes in Berland (dfs搜索)
    CodeForces 723C Polycarp at the Radio (题意题+暴力)
    CodeForces 723B Text Document Analysis (水题模拟)
    CodeForces 723A The New Year: Meeting Friends (水题)
    hdu 1258
    hdu 2266 dfs+1258
  • 原文地址:https://www.cnblogs.com/Susie-/p/10413940.html
Copyright © 2011-2022 走看看