# -*- coding: utf-8 -*-
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys


class Test00():
    def setup_method(self, method):
        self.driver = webdriver.Chrome()
        self.vars = {}

    def teardown_method(self, method):
        self.driver.quit()

    def wait_for_window(self, timeout=2):
        time.sleep(round(timeout / 1000))
        wh_now = self.driver.window_handles
        wh_then = self.vars["window_handles"]
        if len(wh_now) > len(wh_then):
            return set(wh_now).difference(set(wh_then)).pop()

    def test_00(self):
        # Test name: 00
        # Step # | name | target | value | comment
        # 1 | open | / |  |
        self.driver.get("https://www.shiyanlou.com/")
        # 2 | setWindowSize | 1366x648 |  |
        self.driver.set_window_size(1366, 648)
        # 3 | mouseOver | linkText=社区 |  |
        element = self.driver.find_element(By.LINK_TEXT, "社区")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        # 4 | mouseOver | linkText=Python |  |
        element = self.driver.find_element(By.LINK_TEXT, "Python")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        # 5 | mouseOut | linkText=Python |  |
        element = self.driver.find_element(By.LINK_TEXT, "Linux")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        # 6 | click | linkText=Linux 基础入门（新版） |  |
        self.driver.find_element(By.LINK_TEXT, "Linux 基础入门（新版）").click()
        # 7 | runScript | window.scrollTo(0,40) |  |
        self.driver.execute_script("window.scrollTo(0,40)")
        # 8 | click | css=.item:nth-child(1) .item-name |  |
        self.driver.find_element(By.XPATH, "//button[@id=\'__BVID__68__BV_button_\']").click()
        # 9 | click | linkText=ROS1中文维基 |  |
        self.vars["window_handles"] = self.driver.window_handles
        # 10 | storeWindowHandle | root |  |
        self.driver.find_element(By.LINK_TEXT, "ROS1中文维基").click()
        # 11 | selectWindow | handle=${win2249} |  |
        self.vars["win2249"] = self.wait_for_window(2000)
        # 12 | close |  |  |
        self.vars["root"] = self.driver.current_window_handle
        # 13 | selectWindow | handle=${root} |  |
        self.driver.switch_to.window(self.vars["win2249"])
        # 14 | close |  |  |
        self.driver.close()
        # 15 | selectWindow | handle=${undefined} |  |
        self.driver.switch_to.window(self.vars["root"])
        self.driver.close()
        self.driver.switch_to.window(self.vars["undefined"])

