From 8439ec78b5e76cada81c3b7d25114e928a663437 Mon Sep 17 00:00:00 2001 From: 20220007 <20220007@edu.com> Date: Sun, 7 Apr 2024 10:05:19 +0800 Subject: [PATCH] ADD file via upload --- TestBaiDu.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 TestBaiDu.java diff --git a/TestBaiDu.java b/TestBaiDu.java new file mode 100644 index 0000000..ec486e7 --- /dev/null +++ b/TestBaiDu.java @@ -0,0 +1,51 @@ +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 + "’"); + } +} -- 2.34.1