jck28-lucio-web浏览器控制

浏览器控制

打开网页

  • get方法打开浏览器
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/");
    }
}

刷新

  • 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 windowRefresh() {
        driver.get("https://ceshiren.com/");
        driver.navigate().refresh();
    }
}

回退

  • 用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 windowBack() {
        driver.get("https://ceshiren.com/");
        driver.get("https://www.baidu.com/");
        driver.navigate().back();
    }
}

前进

  • 使用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 windowForward() {
        driver.get("https://ceshiren.com/");
        driver.get("https://www.baidu.com/");
        driver.navigate().back();
        driver.navigate().forward();
    }
}

最大化

  • maximize_window方法使窗口最大化
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();
    }
}

最小化

  • minimize_window方法使窗口最小化
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();
    }
}