Best Python code snippet using SeleniumBase
script.py
Source:script.py
...204 self.ext_installed_l.Content = \205 'Installed under:\n{}' \206 .format(ext_pkg_item.ext_pkg.is_installed)207 else:208 self.hide_element(self.ext_installed_l)209210 # Update dependencies211 if ext_pkg_item.ext_pkg.dependencies:212 self.show_element(self.ext_dependencies_l)213 self.ext_dependencies_l.Content = \214 'Dependencies:\n' + \215 ', '.join(ext_pkg_item.ext_pkg.dependencies)216 else:217 self.hide_element(self.ext_dependencies_l)218219 def _update_toggle_button(self, enable=True, multiple=False):220 self.show_element(self.ext_toggle_b)221 if enable:222 self.ext_toggle_b.Content = \223 self.ext_toggle_b.Content.replace('Dis', 'En')224 else:225 self.ext_toggle_b.Content = \226 self.ext_toggle_b.Content.replace('En', 'Dis')227 228 if multiple:229 self.ext_toggle_b.Content = \230 self.ext_toggle_b.Content.replace('Extension', 'Extensions')231 else:232 self.ext_toggle_b.Content = \233 self.ext_toggle_b.Content.replace('Extensions', 'Extension')234235 def _update_ext_action_buttons(self, ext_pkg_items):236 """Updates the status of actions buttons depending on the status of237 the provided ext_pkg_item. e.g. disable the Install button if the238 package is already installed.239240 Args:241 ext_pkg_items: Extension packages to update the action buttons242 """243 if len(ext_pkg_items) == 1:244 ext_pkg_item = ext_pkg_items[0]245 if ext_pkg_item.ext_pkg.is_installed:246 # Action Button: Install247 self.hide_element(self.ext_install_b)248249 # Action Button: Remove250 if ext_pkg_item.ext_pkg.builtin:251 self.hide_element(self.ext_remove_b)252 else:253 self.show_element(self.ext_remove_b)254255 # Action Button: Toggle (Enable / Disable)256 if ext_pkg_item.ext_pkg.is_cli_ext:257 self.hide_element(self.ext_toggle_b)258 else:259 self._update_toggle_button(260 enable=ext_pkg_item.ext_pkg.config.disabled261 )262 else:263 self.show_element(self.ext_install_b)264 self.hide_element(self.ext_toggle_b, self.ext_remove_b)265 elif len(ext_pkg_items) > 1:266 self.hide_element(self.ext_update_b)267 self.hide_element(self.ext_install_b)268 self.hide_element(self.ext_remove_b)269 # hide the button if includes any cli extensions270 if any([x.ext_pkg.is_cli_ext for x in ext_pkg_items]):271 self.hide_element(self.ext_toggle_b)272 # hide the button if any ext is not installed273 elif any([not x.ext_pkg.is_installed for x in ext_pkg_items]):274 self.hide_element(self.ext_toggle_b)275 else:276 all_disabled = \277 [x.ext_pkg.config.disabled for x in ext_pkg_items]278 if all(all_disabled):279 self._update_toggle_button(enable=True, multiple=True)280 return281282 all_enabled = \283 [not x.ext_pkg.config.disabled for x in ext_pkg_items]284 if all(all_enabled):285 self._update_toggle_button(enable=False, multiple=True)286 return287 # hide the button if mixed enabled and disabled288 self.hide_element(self.ext_toggle_b)289290 def _update_ext_settings_panel(self, ext_pkg_item):291 """Updates the package settings panel based on the provided292 package in ext_pkg_item293294 Args:295 ext_pkg_item: Extension package to update the settings ui296297 """298299 if ext_pkg_item.Builtin:300 self.hide_element(self.extCredentials)301 self.hide_element(self.ext_update_b)302 else:303 self.show_element(self.extCredentials)304 self.show_element(self.ext_update_b)305 try:306 # Is package using a private git repo?307 self.privaterepo_cb.IsChecked = \308 ext_pkg_item.ext_pkg.config.private_repo309 self.privaterepo_cb.UpdateLayout()310311 # Set current username and pass for the private repo312 self.repousername_tb.Text = ext_pkg_item.ext_pkg.config.username313 self.repopassword_tb.Text = ext_pkg_item.ext_pkg.config.password314 except Exception:315 self.privaterepo_cb.IsChecked = False316 self.repopassword_tb.Text = self.repousername_tb.Text = ''317318 def _list_options(self, option_filter=None):319 if option_filter:320 option_filter = option_filter.lower()321 self.extpkgs_lb.ItemsSource = \322 [x for x in self._exts_list323 if option_filter in x.searchable_values().lower()]324 else:325 self.extpkgs_lb.ItemsSource = self._exts_list326327 def search_txt_changed(self, sender, args):328 if self.search_tb.Text == '':329 self.hide_element(self.clrsearch_b)330 else:331 self.show_element(self.clrsearch_b)332333 self._list_options(option_filter=self.search_tb.Text.lower())334335 def clear_search(self, sender, args):336 self.search_tb.Text = ' '337 self.search_tb.Clear()338 self.extpkgs_lb.ItemsSource = self._exts_list339340 def update_ext_info(self, sender, args):341 """Callback for updating info panel on package selection change342 """343 if self.selected_pkg:344 self.show_element(self.ext_infostack)345 self.show_element(self.ext_infopanel)346 self._update_ext_info_panel(self.selected_pkg)347 self._update_ext_action_buttons([self.selected_pkg])348 self._update_ext_settings_panel(self.selected_pkg)349 elif self.selected_pkgs:350 self.hide_element(self.ext_infostack)351 self.hide_element(self.extCredentials)352 self._update_ext_action_buttons(self.selected_pkgs)353 else:354 self.hide_element(self.ext_infopanel)355356 def handle_private_repo(self, sender, args):357 """Callback for updating private status of a package358 """359 if self.privaterepo_cb.IsChecked:360 self.accountcreds_dp.IsEnabled = True361 else:362 self.accountcreds_dp.IsEnabled = False363364 def handle_install_button_popup(self, sender, args):365 """Callback for Install package destination context menu366367 This callback method will popup a menu with a list of install368 destinations, when the install button is clicked.
...
__init__.py
Source:__init__.py
...23class CopyFromView(TemplateWindow):24 xaml_source = 'CopyViews.xaml'25 26 def _setup(self, **kwargs):27 self.hide_element(self.clrsuffix_b)28 self.hide_element(self.clrprefix_b)29 self.clear_suffix(None, None)30 self.clear_prefix(None, None)31 self.prefix.Focus()32 33 for i in kwargs['list']:34 if i is None:35 continue36 if type(i) == str:37 self.purpose.AddText(i)38 button_name = kwargs.get('button_name', None)39 if button_name:40 self.select_b.Content = button_name41 42 self.checkDetail.IsChecked = True43 44 def button_select(self, sender, args):45 if self.suffix.Text:46 suffix = self.suffix.Text47 else:48 suffix = ""49 if self.prefix.Text:50 prefix = self.prefix.Text51 else:52 prefix = ""53 if self.purpose.Text:54 purpose = self.purpose.Text55 else:56 purpose = ""57 detail = self.checkDetail.IsChecked58 self.response = {"suffix": suffix,59 "prefix": prefix,60 "purpose": purpose,61 "detail": detail}62 self.Close()63 def suffix_txt_changed(self, sender, args):64 """Handle text change in search box."""65 if self.suffix.Text == '':66 self.hide_element(self.clrsuffix_b)67 else:68 self.show_element(self.clrsuffix_b)69 70 def prefix_txt_changed(self, sender, args):71 """Handle text change in search box."""72 if self.prefix.Text == '':73 self.hide_element(self.clrprefix_b)74 else:75 self.show_element(self.clrprefix_b)76 def clear_suffix(self, sender, args):77 """Clear search box."""78 self.suffix.Text = ''79 self.suffix.Clear()80 self.suffix.Focus81 82 def clear_prefix(self, sender, args):83 """Clear search box."""84 self.prefix.Text = ''85 self.prefix.Clear()86 self.prefix.Focus87class InputFormNumber(TemplateWindow):88 xaml_source = 'InputNumber.xaml'89 def _setup(self, **kwargs):90 self.hide_element(self.clrsearch_b)91 self.clear_search(None, None)92 self.search_tb.Focus()93 94 button_name = kwargs.get('button_name', None)95 if button_name:96 self.select_b.Content = button_name97 98 head = kwargs.get('head', None)99 if head:100 self.head.Text = head101 102 def button_select(self, sender, args):103 """Handle select button click."""104 if self.search_tb.Text:105 self.response = self.search_tb.Text106 self.Close()107 def search_txt_changed(self, sender, args):108 """Handle text change in search box."""109 if self.search_tb.Text == '':110 self.hide_element(self.clrsearch_b)111 else:112 self.show_element(self.clrsearch_b)113 def clear_search(self, sender, args):114 """Clear search box."""115 self.search_tb.Text = ' '116 self.search_tb.Clear()117 self.search_tb.Focus()118class InputFormText(TemplateWindow):119 xaml_source = 'InputText.xaml'120 def _setup(self, **kwargs):121 self.hide_element(self.clrsearch_b)122 self.clear_search(None, None)123 self.search_tb.Focus()124 125 button_name = kwargs.get('button_name', None)126 if button_name:127 self.select_b.Content = button_name128 129 head = kwargs.get('head', None)130 if head:131 self.head.Text = head132 133 def button_select(self, sender, args):134 """Handle select button click."""135 if self.search_tb.Text:136 self.response = self.search_tb.Text137 else:138 self.response = None139 self.Close()140 def search_txt_changed(self, sender, args):141 """Handle text change in search box."""142 if self.search_tb.Text == '':143 self.hide_element(self.clrsearch_b)144 else:145 self.show_element(self.clrsearch_b)146 def clear_search(self, sender, args):147 """Clear search box."""148 self.search_tb.Text = ' '149 self.search_tb.Clear()150 self.search_tb.Focus()151class CopyUserView(TemplateWindow):152 xaml_source = 'CopyUser.xaml'153 154 def _setup(self, **kwargs):155 self.hide_element(self.clrpurpose_b)156 self.hide_element(self.clrprefix_b)157 self.clear_purpose(None, None)158 self.clear_prefix(None, None)159 self.purpose.Focus()160 161 button_name = kwargs.get('button_name', None)162 if button_name:163 self.select_b.Content = button_name164 165 def button_select(self, sender, args):166 if self.prefix.Text:167 prefix = self.prefix.Text168 else:169 return170 if self.purpose.Text:171 purpose = self.purpose.Text172 else:173 return174 self.response = {"prefix": prefix,175 "purpose": purpose,176 "suffix": ''}177 self.Close()178 def purpose_txt_changed(self, sender, args):179 """Handle text change in search box."""180 if self.purpose.Text == '':181 self.hide_element(self.clrpurpose_b)182 else:183 self.show_element(self.clrpurpose_b)184 185 def prefix_txt_changed(self, sender, args):186 """Handle text change in search box."""187 if self.prefix.Text == '':188 self.hide_element(self.clrprefix_b)189 else:190 self.show_element(self.clrprefix_b)191 def clear_purpose(self, sender, args):192 """Clear search box."""193 self.purpose.Text = ''194 self.purpose.Clear()195 self.purpose.Focus196 197 def clear_prefix(self, sender, args):198 """Clear search box."""199 self.prefix.Text = ''200 self.prefix.Clear()201 self.prefix.Focus202class ReserveProjectForm(TemplateWindow):203 xaml_source = 'ReserveProject.xaml'204 def _setup(self, **kwargs):205 self.hide_element(self.clrsearch_b)206 self.clear_search(None, None)207 self.search_tb.Focus()208 209 button_name = kwargs.get('button_name', None)210 if button_name:211 self.select_b.Content = button_name212 213 head = kwargs.get('head', None)214 if head:215 self.head.Text = head216 default_folder = kwargs.get('folder', None)217 if default_folder:218 self.hasFolder = True219 self.dir_name.Text = default_folder220 else:221 self.hasFolder = False222 223 def pick_folder(self, sender, args):224 """Pick folder."""225 folderBrowserDialog = FolderBrowserDialog()226 folderBrowserDialog.Description = "ÐÑбеÑиÑе Ð¿Ð°Ð¿ÐºÑ Ð´Ð»Ñ ÑоÑ
ÑÐ°Ð½ÐµÐ½Ð¸Ñ ÑезеÑвной копии."227 folderBrowserDialog.ShowNewFolderButton = True228 if folderBrowserDialog.ShowDialog() == DialogResult.OK:229 folderName = folderBrowserDialog.SelectedPath230 self.dir_name.Text = folderName231 self.hasFolder = True232 # self.dir_name.Foreground = Brush.SolidColorBrush(Colors.Black)233 234 def button_select(self, sender, args):235 """Handle select button click."""236 if self.hasFolder:237 res = {}238 if self.search_tb.Text:239 res["suffix"] = self.search_tb.Text240 else:241 res["suffix"] = None242 res["folder"] = self.dir_name.Text243 self.response = res244 self.Close()245 # else:246 # self.dir_name.Foreground = Brush.SolidColorBrush(Colors.Red)247 def search_txt_changed(self, sender, args):248 """Handle text change in search box."""249 if self.search_tb.Text == '':250 self.hide_element(self.clrsearch_b)251 else:252 self.show_element(self.clrsearch_b)253 def clear_search(self, sender, args):254 """Clear search box."""255 self.search_tb.Text = ' '256 self.search_tb.Clear()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!