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.WebDriverUtil;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;

@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);
        FirefoxDriver driver = new FirefoxDriver();
        String url = "https://qxmugen.com/";
        driver.get(url);
        seleniumExecutor.setDriver(driver);
        seleniumExecutor.setInputs(inputs);
        seleniumExecutor.execute(url);
//        String currentwindowHandle;
//        Queue<String> windowHandles = Queues.newLinkedBlockingDeque(driver.getWindowHandles());
//        System.out.println(windowHandles);
//        driver.findElement(By.xpath("/html/body/div[5]/div[3]/div[1]/div/div/div[2]/div/div[4]/a")).click();
//        System.out.println("Current Url:"+driver.getCurrentUrl());
//        System.out.println("has Window:"+driver.getWindowHandles().size());
//
//
//        windowHandles = Queues.newLinkedBlockingDeque(driver.getWindowHandles());
//        System.out.println(windowHandles);
//
//        driver.findElement(By.xpath("/html/body/div[5]/div[3]/div[1]/div/div/div[2]/div/div[4]/a")).click();
//
//        windowHandles = Queues.newLinkedBlockingDeque(driver.getWindowHandles());
//        System.out.println(windowHandles);


    }
}
