zoukankan      html  css  js  c++  java
  • Test


    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;
    import org.testng.annotations.DataProvider;
    import java.util.concurrent.TimeUnit;

    import org.junit.Assert;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxProfile;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.WebDriverWait;

    public class demo
    {
    private WebDriver driver;

    @DataProvider
    public Object[][] dataObjects()
    {
    Object[][] data = { { "https://www.baidu.com/", "selenium" } };
    return data;
    }

    @BeforeMethod(alwaysRun = true)
    public void beforeTest()
    {
    FirefoxProfile profile = new FirefoxProfile();
    driver = new FirefoxDriver(profile);
    }

    @Test(groups = "Search", dataProvider = "dataObjects")
    public void LoginTest(String base_url, String kw) throws InterruptedException
    {
    driver.manage().window().maximize();
    driver.get(base_url);
    driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
    System.out.println(driver.getCurrentUrl());
    WebElement inputBox = driver.findElement(By.id("kw"));
    type(inputBox, kw);
    WebElement searchButton = (new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>()
    {
    @Override
    public WebElement apply(WebDriver d)
    {
    return d.findElement((By.cssSelector("input#su")));
    }
    });

    searchButton.submit();
    Thread.sleep(6000);
    Assert.assertTrue(driver.getTitle().contains(kw));

    }

    @AfterMethod(alwaysRun = true)
    public void afterTearDown()
    {
    driver.quit();
    }

    /**
    * @author Young
    * @param e
    * @param str
    * @throws InterruptedException
    */
    public static void type(WebElement e, String str) throws InterruptedException
    {
    String[] singleCharacters = str.split("");
    // Interval is 0.5 second between each type of character, this is to
    // simulate real human action
    for (int i = 0; i < singleCharacters.length; i++)
    {
    if (singleCharacters[i] != "")
    {
    e.sendKeys(singleCharacters[i]);
    Thread.sleep(500);
    }
    }
    Thread.sleep(1000);

    }

    }

  • 相关阅读:
    单相全桥逆变电路工作过程
    单片机实用工具大全
    电路元件
    IC SPEC相关数据
    庖丁解牛,经典运放电路分析
    microstrip(微带线)、stripline(带状线) 指什么?
    [转]关于时钟线/数据线/地址线上串联电阻及其作用
    正激变换电路工作原理
    从Buck-Boost到Flyback
    [转载].关于耦合电容、滤波电容、去耦电容、旁路电容作用
  • 原文地址:https://www.cnblogs.com/tobecrazy/p/4984551.html
Copyright © 2011-2022 走看看