Skip to content

Commit

Permalink
add test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Dou Du committed May 30, 2024
1 parent 9cee9bc commit ac17d7a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Selenium IDE
import pytest
import time
import json
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
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 test_widget():
def setup_method(self, method):
options = Options()
cwd = os.getcwd()
options.add_experimental_option("prefs", {"download.default_directory": cwd})
self.driver = webdriver.Chrome(options=options)
self.vars = {}

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

def download_widget_image(self):
self.driver.get("http://localhost:8383/voila/render/example.ipynb")
self.driver.set_window_size(1280, 720)
time.sleep(3)
self.driver.save_screenshot("widget-01.png")
self.driver.execute_script("window.scrollTo(0, 1000)")
time.sleep(3)
self.driver.save_screenshot("widget-02.png")

test = test_widget()
test.setup_method('Chrome')
test.download_widget_image()
test.teardown_method('Chrome')

12 changes: 12 additions & 0 deletions test/test_figures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from PIL import Image, ImageChops, ImageStat

image1 = Image.open('widget-01.png')
image2 = Image.open('test/widget-sample.png')

diff = ImageChops.difference(image1, image2)
stat = ImageStat.Stat(diff)

if sum(stat.mean) == 0:
print('images are the same')
else:
raise Exception("The result is NOT the same as expected. Please check matplotlib version.")
Binary file added test/widget-sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac17d7a

Please sign in to comment.