# Generated by Selenium IDE
import pytest
import time
import json
import sys
import subprocess
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
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class TestTest01():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_test01(self):
    #a = subprocess.check_output(['jupyter server list'], shell=True)
    #print("The jupyter server:", a)
    #url = a.split(b'\n')[1].decode("utf-8").split(' ')[0]
    self.driver.get("http://localhost:8888")
    self.driver.set_window_size(1500, 1000)
    #self.driver.execute_script("window.scrollTo(0, 200)")
    time.sleep(10)

    self.driver.save_screenshot("jupyterlab-extension1.png")

    try:
        self.driver.find_element(By.CSS_SELECTOR, ".jp-LauncherCard:nth-child(5) svg").click()
    except:
        pass

    time.sleep(5)
    self.driver.save_screenshot("jupyterlab-extension2.png")

    try:
        element = self.driver.find_element(By.XPATH, "//span[text()='binder']")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
    except Exception as e:
        print("----------------------------")
        print("----------------------------")
        print(e)
        print("----------------------------")
        pass
    
    time.sleep(5)
    self.driver.save_screenshot("jupyterlab-extension3.png")

    try:
        elements = self.driver.find_elements(By.CLASS_NAME, "makeStyles-iconButton-10")
        for el in elements:
            el.click()
            time.sleep(3)
    except Exception as e:
        print("----------------------------")
        print("----------------------------")
        print(e)
        print("----------------------------")
        pass

    time.sleep(5)
    self.driver.save_screenshot("jupyterlab-extension4.png")

test = TestTest01()
test.setup_method('Chrome')
test.test_test01()
test.teardown_method('Chrome')

