• 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);

    }

    }

  • 相关阅读:
    【整理】uclibc,eglibc,glibc之间的区别和联系
    C语言calloc()函数:分配内存空间并初始化——stm32中的应用
    收藏!了解UART总线工作原理看这一篇就够了!
    在stm32开发可以调用c标准库的排序和查找 qsort bsearch
    更少的直接百度,更多的取看API
    Sping中的IOC四种注解的简单记录
    使用for循环还是foreach循环?
    总是要还的
    EL表达式,保留小数点后两位
    如何遍历二叉树
  • 原文地址:https://www.cnblogs.com/tobecrazy/p/4984551.html
Copyright © 2020-2023  润新知