浏览器控制
打开网页
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowGet() {
driver.get("https://ceshiren.com/");
}
}
刷新
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowRefresh() {
driver.get("https://ceshiren.com/");
driver.navigate().refresh();
}
}
回退
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowBack() {
driver.get("https://ceshiren.com/");
driver.get("https://www.baidu.com/");
driver.navigate().back();
}
}
前进
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowForward() {
driver.get("https://ceshiren.com/");
driver.get("https://www.baidu.com/");
driver.navigate().back();
driver.navigate().forward();
}
}
最大化
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowMax() {
driver.get("https://ceshiren.com/");
driver.manage().window().maximize();
}
}
最小化
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.time.Duration;
/**
* @Author: 霍格沃兹测试开发学社
* @Desc: '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
*/
public class WindowTest {
public static WebDriver driver;
@BeforeAll
static void setUpAll() {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterAll
static void tearDownAll(){
driver.quit();
}
@Test
void windowMin() {
driver.get("https://ceshiren.com/");
driver.manage().window().minimize();
}
}