package com.zjty.autotest;

import com.google.common.collect.Lists;
import com.zjty.autotest.pojo.report.Measure;
import com.zjty.autotest.pojo.report.Report;
import com.zjty.autotest.pojo.test.Input;
import com.zjty.autotest.pojo.test.Project;
import com.zjty.autotest.service.impl.SeleniumExecutor;
import com.zjty.autotest.util.WebDriverUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.logging.LogEntry;
import org.openqa.selenium.logging.LogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@Slf4j
@SpringBootTest
class AutotestApplicationTests {

    @Autowired
    SeleniumExecutor seleniumExecutor;

    @Test
    public void execute() throws InterruptedException {
        String url = "file:///C:/code/errorTest.html";
//        String url = "https://bbs.colg.cn/forum-171-1.html";
        test1(url);



    }

    private void test1(String url){
        WebDriver driver = WebDriverUtil.getWebDriver("firefox");
        driver.get(url);
        for (String s : driver.manage().logs().getAvailableLogTypes()) {
            System.out.println(s);
        }
    }

    private void test2(String url) {
        List<Input> inputs = Lists.newArrayList();
        inputs.add(new Input(null, null, null, "caozuoyuan123"));
        inputs.add(new Input(null, null, null, "caozuoyuan"));

        Project project = new Project(
                null,
                null,
                "firefox",
                url,
                inputs
        );
        Report report = seleniumExecutor.execute(project);
        for (Measure measure : report.getMeasures()) {
            System.out.println(measure);
        }
    }



}
