5
5
from build_assets .selenium_runner .enums import IcomoonPage , IcomoonAlerts
6
6
7
7
class PeekSeleniumRunner (SeleniumRunner ):
8
- def peek (self , svgs : List [str ], screenshot_folder : str ):
8
+ def peek (self , svgs : List [str ], screenshot_folder : str , icon_info : dict ):
9
9
"""
10
10
Upload the SVGs and peek at how Icomoon interpret its SVGs and
11
11
font versions.
12
12
:param svgs: a list of svg Paths that we'll upload to icomoon.
13
13
:param screenshot_folder: the name of the screenshot_folder.
14
+ :param icon_info: a dictionary containing info on an icon. Taken from the devicon.json.
14
15
:return an array of svgs with strokes as strings. These show which icon
15
16
contains stroke.
16
17
"""
17
18
messages = self .peek_svgs (svgs , screenshot_folder )
18
- self .peek_icons (svgs , screenshot_folder )
19
+ self .peek_icons (screenshot_folder , icon_info )
19
20
return messages
20
21
21
22
def peek_svgs (self , svgs : List [str ], screenshot_folder : str ):
@@ -61,10 +62,11 @@ def peek_svgs(self, svgs: List[str], screenshot_folder: str):
61
62
print ("Finished peeking the svgs..." )
62
63
return svgs_with_strokes
63
64
64
- def peek_icons (self , svgs : List [ str ], screenshot_folder : str ):
65
+ def peek_icons (self , screenshot_folder : str , icon_info : dict ):
65
66
"""
66
67
Peek at the icon versions of the SVGs that were uploaded.
67
68
:param screenshot_folder: the name of the screenshot_folder.
69
+ :param icon_info: a dictionary containing info on an icon. Taken from the devicon.json.
68
70
"""
69
71
print ("Begin peeking at the icons..." )
70
72
# ensure all icons in the set is selected.
@@ -85,7 +87,7 @@ def peek_icons(self, svgs: List[str], screenshot_folder: str):
85
87
main_content = self .driver .find_element_by_xpath (main_content_xpath )
86
88
main_content .screenshot (new_icons_path );
87
89
88
- # go downward so we get the oldest icon first
90
+ # go in reverse order so we get the oldest icon first
89
91
icon_divs_xpath = f'//div[@id="glyphSet0"]/div'
90
92
icon_divs = self .driver .find_elements_by_xpath (icon_divs_xpath )
91
93
icon_divs .reverse ()
@@ -98,6 +100,23 @@ def peek_icons(self, svgs: List[str], screenshot_folder: str):
98
100
Path (screenshot_folder , f"new_icon_{ i } .png" ).resolve ()
99
101
)
100
102
icon_div .screenshot (icon_screenshot )
103
+
104
+ i += 1
105
+
106
+ # test the colors
107
+ style = "#glyphSet0 span:first-of-type {color: " + icon_info ["color" ] + "}"
108
+ script = f"document.styleSheets[0].insertRule({ style } , 0)"
109
+ self .driver .execute_script (script )
110
+ i = 0
111
+ for icon_div in icon_divs :
112
+ if not icon_div .is_displayed ():
113
+ continue
114
+
115
+ icon_screenshot = str (
116
+ Path (screenshot_folder , f"new_colored_icon_{ i } .png" ).resolve ()
117
+ )
118
+ icon_div .screenshot (icon_screenshot )
119
+
101
120
i += 1
102
121
103
122
print ("Finished peeking the icons..." )
0 commit comments