package com.zjty.autotest;

import com.google.common.collect.Maps;
import com.google.common.collect.Queues;
import com.zjty.autotest.service.SeleniumExecutor;
import com.zjty.autotest.util.FileUtil;
import com.zjty.autotest.util.WebDriverUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;
import java.util.logging.Level;

@Slf4j
@SpringBootTest
class AutotestApplicationTests {

    @Autowired
    SeleniumExecutor seleniumExecutor;

    @Test
    public void execute() {
        Map<String, String> inputs = Maps.newHashMap();
        inputs.put("name", "root");
        inputs.put("password", "root");
        System.setProperty("webdriver.firefox.driver", WebDriverUtil.FIRE_FOX_EXE);
        DesiredCapabilities caps = DesiredCapabilities.firefox();
        LoggingPreferences logPrefs = new LoggingPreferences();
        logPrefs.enable(LogType.BROWSER, Level.ALL);
        caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
        WebDriver driver = new FirefoxDriver();
        String url = "file:///C:/Users/C/Documents/WeChat%20Files/c18042003295/FileStorage/File/2020-03/test1.html";
        long startTime = System.currentTimeMillis();
        driver.get(url);
        long endTime = System.currentTimeMillis();
        long costTime = endTime - startTime;
        log.info("当前URL：{}  响应时间 {} ms  开始进行遍历...", url, costTime);
        driver.findElement(By.xpath("/html/body/div/span")).click();

    }
}
