You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.hogwarts.webui;
import com.hogwarts.base.*;
import org.apache.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
public class TestBaiDu extends WebUIBase {
private Logger logger = Logger.getLogger(TestBaiDu.class);
@Test
public void baiduSearch1() throws Exception{
String checkString = "今日头条";
baiduSearch(checkString);
}
@Test
public void baiduSearch2() throws Exception{
String checkString = "王者荣耀";
baiduSearch(checkString);
}
/**
* 百度搜索公共子函数
*
* @param checkString 搜索关键词
* @throws Exception
*/
public void baiduSearch(String checkString) throws Exception {
testcaseName = "Baidu search UI automation test.";
logger.info("Start the automation test: " + testcaseName);
//浏览器中打开百度
logger.info("Open the www.baidu.com");
navigation.to("http://www.baidu.com");
wait5s();
//输入搜索内容Selenium
WebUITasks.inputText(checkString,driver);
wait5s();
//单击搜索按钮
WebUITasks.clickSearchBtn(driver);
wait5s();
String browserTitle = driver.getTitle();
Assertions.assertTrue(browserTitle.contains(checkString) || browserTitle.contains("安全验证")
, "Check if the web page contains the key word " + checkString + "");
}
}