Best Python code snippet using SeleniumBase
hack_the_planet.py
Source:hack_the_planet.py
...39 self.highlight(".tocsection-5 span.toctext", loops=1, scroll=False)40 self.highlight(".tocsection-6 span.toctext", loops=1, scroll=False)41 self.highlight(".tocsection-7 span.toctext", loops=2, scroll=False)42 zoom_in = "div.thumbinner{zoom: 1.4;-moz-transform: scale(1.4);}"43 self.add_css_style(zoom_in)44 self.highlight("div.thumbinner", loops=8, scroll=False)45 self.open("https://www.apple.com/store")46 self.set_text_content("div.rs-shop-subheader", aybabtu)47 self.set_text_content('#shelf-1 a[href*="mac"]', "ALL")48 self.set_text_content('#shelf-1 a[href*="iphone"]', "YOUR")49 self.set_text_content('#shelf-1 a[href*="ipad"]', "BASE")50 self.set_text_content('#shelf-1 a[href*="watch"]', "ARE")51 self.set_text_content('#shelf-1 a[href*="airpods"]', "BELONG")52 self.set_text_content('#shelf-1 a[href*="airtag"]', "TO")53 self.set_text_content('#shelf-1 a[href*="tv"]', "US")54 self.set_text_content('#shelf-1 a[href*="homepod"]', ".")55 self.set_text_content("h2", aybabtu + ". ")56 self.highlight("div.rs-shop-subheader", loops=6, scroll=False)57 self.highlight("#shelf-1", loops=2, scroll=False)58 self.highlight('#shelf-1 a[href*="mac"]', loops=1, scroll=False)59 self.highlight('#shelf-1 a[href*="iphone"]', loops=1, scroll=False)60 self.highlight('#shelf-1 a[href*="ipad"]', loops=3, scroll=False)61 self.highlight('#shelf-1 a[href*="watch"]', loops=1, scroll=False)62 self.highlight('#shelf-1 a[href*="airpods"]', loops=1, scroll=False)63 self.highlight('#shelf-1 a[href*="airtag"]', loops=1, scroll=False)64 self.highlight('#shelf-1 a[href*="tv"]', loops=3, scroll=False)65 self.highlight("h2", loops=9, scroll=False)66 self.open("https://google.com/ncr")67 self.set_text_content('a[href*="about.google"]', ayb)68 self.set_text_content('a[href*="store.google"]', abtu)69 self.set_text_content('a[href*="mail.google.com"]', ayb)70 self.set_text_content('a[href*="google.com/img"]', abtu)71 self.set_attributes('[value="Google Search"]', "value", ayb)72 self.set_attributes('[value="I\'m Feeling Lucky"]', "value", abtu)73 zoom_in = "a{zoom: 1.2;-moz-transform: scale(1.2);}"74 self.add_css_style(zoom_in)75 zoom_in = (76 '[value="ALL YOUR BASE"]{zoom: 1.3;-moz-transform: scale(1.3);}'77 '[value="ARE BELONG TO US"]{zoom: 1.3;-moz-transform: scale(1.3);}'78 )79 self.add_css_style(zoom_in)80 self.highlight('a[href*="about.google"]', loops=3)81 self.highlight('a[href*="store.google"]', loops=3)82 self.highlight('a[href*="mail.google.com"]', loops=3)83 self.highlight('a[href*="google.com/img"]', loops=3)84 self.highlight('form[role="search"]', loops=8)85 self.open("https://twitter.com/")86 if not self.is_element_visible('a[href*="w/signup"] span'):87 self.refresh()88 if self.is_element_visible('a[href*="w/signup"] span'):89 self.set_text_content('a[href*="w/signup"] span', aybabtu)90 self.highlight('a[href*="w/signup"] span', loops=6, scroll=False)91 self.highlight('a[href*="w/signup"]', loops=6, scroll=False)92 self.open("https://www.youtube.com/")93 self.set_text_content("%s(1)" % yt_chip, "ALL")94 self.set_text_content("%s(2)" % yt_chip, "YOUR")95 self.set_text_content("%s(3)" % yt_chip, "BASE")96 self.set_text_content("%s(4)" % yt_chip, "ARE")97 self.set_text_content("%s(5)" % yt_chip, "BELONG")98 self.set_text_content("%s(6)" % yt_chip, "TO")99 self.set_text_content("%s(7)" % yt_chip, "US")100 self.set_text_content("%s(8)" % yt_chip, "!")101 self.set_text_content("%s(9)" % yt_chip, "!")102 self.set_text_content("%s(10)" % yt_chip, "!")103 self.click_if_visible("#dismiss-button")104 self.click_if_visible('button[aria-label="Close"]')105 self.highlight("#scroll-container", loops=5, scroll=False)106 self.highlight("%s(1)" % yt_chip, loops=1, scroll=False)107 self.highlight("%s(2)" % yt_chip, loops=1, scroll=False)108 self.highlight("%s(3)" % yt_chip, loops=3, scroll=False)109 self.highlight("%s(4)" % yt_chip, loops=1, scroll=False)110 self.highlight("%s(5)" % yt_chip, loops=1, scroll=False)111 self.highlight("%s(6)" % yt_chip, loops=1, scroll=False)112 self.highlight("%s(7)" % yt_chip, loops=3, scroll=False)113 self.highlight("#scroll-container", loops=7, scroll=False)114 self.open("https://github.com/features/actions")115 self.set_text_content('a[href="/team"]', ayb)116 self.set_text_content('a[href="/enterprise"]', abtu)117 self.set_text_content("h1 span:nth-child(1)", ayb)118 self.set_text_content("h1 span:nth-of-type(2)", "ARE")119 self.set_text_content("h1 span:nth-of-type(3)", "BELONG")120 self.set_text_content("h1 span:nth-of-type(4)", "TO")121 self.set_text_content("h1 span:nth-of-type(5)", "US")122 self.type('input[name="q"]', aybabtu.lower())123 self.click("h1", scroll=False)124 self.highlight("nav", loops=5, scroll=False)125 self.highlight('input[name="q"]', loops=5, scroll=False)126 self.highlight("h1", loops=8, scroll=False)127 self.open("https://dev.to/top/infinity")128 self.click_if_visible('button[aria-label="Close campaign banner"]')129 self.set_text_content('nav a[data-text="Relevant"]', "ALL")130 self.set_text_content('nav a[data-text="Latest"]', "YOUR")131 self.set_text_content('nav a[data-text="Top"]', "BASE")132 self.set_text_content('nav a[data-text="Week"]', "ARE")133 self.set_text_content('nav a[data-text="Month"]', "BELONG")134 self.set_text_content('nav a[data-text="Year"]', "TO")135 self.set_text_content('nav a[data-text="Infinity"]', "US")136 self.set_text_content('aside a[class*="tful"]', aybabtu)137 self.set_text_content('aside a[aria-label="Create new account"]', ayb)138 self.set_text_content('aside a[aria-label="Log in"]', abtu)139 self.set_text_content('aside a[class*="tful"]:nth-child(2)', aybabtu)140 self.set_text_content('aside a[class*="tful"]:nth-child(3)', aybabtu)141 self.set_text_content('aside a[class*="tful"]:nth-child(4)', aybabtu)142 self.set_text_content('aside a[class*="tful"]:nth-child(5)', aybabtu)143 self.set_attribute("a.crayons-avatar img", "src", sb_dashboard_logo)144 self.set_text_content(".profile-preview-card button", "SeleniumBase")145 self.set_text_content("h2.crayons-story__title a", aybabtu)146 self.type('input[name="q"]', aybabtu)147 self.highlight('input[name="q"]', loops=4, scroll=False)148 self.highlight('[aria-label="Primary sidebar"] div div', scroll=False)149 self.highlight('nav a[data-text="Relevant"]', loops=1, scroll=False)150 self.highlight('nav a[data-text="Latest"]', loops=1, scroll=False)151 self.highlight('nav a[data-text="Top"]', loops=2, scroll=False)152 self.highlight('nav a[data-text="Week"]', loops=1, scroll=False)153 self.highlight('nav a[data-text="Month"]', loops=1, scroll=False)154 self.highlight('nav a[data-text="Year"]', loops=1, scroll=False)155 self.highlight('nav a[data-text="Infinity"]', loops=2, scroll=False)156 self.highlight('aside[id*="sidebar"] section', loops=5, scroll=False)157 self.highlight("div.crayons-story__body", loops=7, scroll=False)158 self.open("https://azure.microsoft.com/en-us/services/playfab/")159 self.set_text_content("h1", aybabtu)160 self.set_text_content('a[aria-label*="Try PlayF"]', ayb)161 self.set_text_content('a[aria-label*="Sign in to"]', abtu)162 self.set_text_content('span:contains("Chat with Sales")', aybabtu)163 self.highlight("h1", loops=6, scroll=False)164 self.highlight('a[aria-label*="Try PlayF"]', loops=4, scroll=False)165 self.highlight('a[aria-label*="Sign in to"]', loops=4, scroll=False)166 self.highlight("button#live-engage-btn", loops=6, scroll=False)167 self.open("https://www.snapchat.com/")168 self.set_text_content("h1", ayb)169 self.set_text_content("form .button-large span span", abtu)170 zoom_in = "a.button-large span{zoom: 1.2;-moz-transform: scale(1.2);}"171 self.add_css_style(zoom_in)172 self.highlight("h1", loops=6, scroll=False)173 self.highlight("form .button-large span span", loops=8, scroll=False)174 self.open("https://store.steampowered.com/")175 self.set_text_content('div.content a[href*="/about/"]', " ")176 self.set_text_content('div.content a[href*="help.steam"]', aybabtu)177 self.set_text_content("#foryou_tab a", "ALL")178 self.set_text_content("#noteworthy_tab a", "YOUR BASE")179 self.set_text_content("#genre_tab a", "ARE")180 self.set_text_content('span:contains("Points Shop")', "BELONG")181 self.set_text_content('span:contains("News")', "TO")182 self.set_text_content('span:contains("Labs")', "US")183 self.set_value("input#store_nav_search_term", ayb + " . . . .")184 self.highlight('div.content a[href*="help.steam"]', loops=6)185 self.highlight("#store_nav_area", loops=2, scroll=False)186 self.highlight("#foryou_tab a", loops=1, scroll=False)187 self.highlight("#noteworthy_tab a", loops=3, scroll=False)188 self.highlight("#genre_tab a", loops=1, scroll=False)189 self.highlight('span:contains("BELONG")', loops=1, scroll=False)190 self.highlight('span:contains("TO")', loops=1, scroll=False)191 self.highlight('span:contains("US")', loops=2, scroll=False)192 self.js_click('input[id*="nav_search"]')193 self.highlight('input[id*="nav_search"]', loops=6, scroll=False)194 self.open("https://xkcd.com/286/")195 self.set_text_content('a[href="/archive"]', "ALL")196 self.set_text_content('a[href*="what-if"]', "YOUR")197 self.set_text_content('a[href*="//blag."]', "BASE")198 self.set_text_content('a[href*="/about"]', abtu)199 self.remove_element('li:contains("Feed")')200 self.remove_element('li:contains("TW")')201 self.remove_element('li:contains("Books")')202 self.remove_element('li:contains("What")')203 self.remove_element('li:contains("WI")')204 self.set_attributes("#news img", "src", sb_banner_logo)205 self.set_text_content("#ctitle", aybabtu)206 self.set_text_content('a[rel="prev"]', "All")207 self.set_text_content('a[href*="random"]', "Your")208 self.set_text_content('a[rel="next"]', "Base")209 self.highlight("#topLeft ul", loops=5, scroll=False)210 self.highlight('a[href="/archive"]', loops=1, scroll=False)211 self.highlight('a[href*="what-if"]', loops=1, scroll=False)212 self.highlight('a[href*="//blag."]', loops=2, scroll=False)213 self.highlight('a[href*="/about"]', loops=5, scroll=False)214 self.highlight('a[rel="prev"]', loops=1, scroll=False)215 self.highlight('a[href*="random"]', loops=1, scroll=False)216 self.highlight('a[rel="next"]', loops=3, scroll=False)217 self.highlight("#ctitle", loops=7, scroll=False)218 self.open("https://www.nintendo.com/whatsnew/")219 self.set_text_content("h1", aybabtu)220 self.highlight("h1", loops=10, scroll=False)221 self.open("https://support.gog.com/hc/en-us?product=gog")222 self.set_text_content("div.intro-title", aybabtu)223 self.set_text_content("h4", aybabtu)224 self.highlight("div.intro-title", loops=8, scroll=False)225 self.highlight("h4", loops=8, scroll=False)226 self.open("https://slack.com/help/articles/204714258-Giphy-for-Slack")227 self.set_text_content("h1", aybabtu)228 self.set_text_content('a[prettyslug="getting-started"]', "ALL")229 self.set_text_content('a[prettyslug="using-slack"]', "YOUR")230 self.set_text_content('a[prettyslug="your-profile"]', "BASE")231 self.set_text_content('a[prettyslug="connect-tools"]', "ARE")232 self.set_text_content('a[prettyslug="administration"]', "BELONG")233 self.set_text_content('a[prettyslug="tutorials"]', "TO US")234 self.highlight("h1", loops=4, scroll=False)235 self.highlight("div#global_menu", loops=2, scroll=False)236 self.highlight('a[prettyslug*="g-started"]', loops=1, scroll=False)237 self.highlight('a[prettyslug="using-slack"]', loops=1, scroll=False)238 self.highlight('a[prettyslug="your-profile"]', loops=2, scroll=False)239 self.highlight('a[prettyslug="connect-tools"]', loops=1, scroll=False)240 self.highlight('a[prettyslug="administration"]', loops=1, scroll=False)241 self.highlight('a[prettyslug="tutorials"]', loops=2, scroll=False)242 self.open("https://kubernetes.io/")243 self.set_text_content('nav a[href="/docs/"]', "ALL")244 self.set_text_content('nav a[href="/blog/"]', "YOUR")245 self.set_text_content('nav a[href="/training/"]', "BASE")246 self.set_text_content('nav a[href="/partners/"]', "ARE")247 self.set_text_content('nav a[href="/community/"]', "BELONG")248 self.set_text_content('nav a[href="/case-studies/"]', "TO")249 self.set_text_content("nav #navbarDropdown", "US")250 self.set_text_content("nav #navbarDropdownMenuLink", ".")251 if self.is_element_visible("h1"):252 self.set_text_content("h1", aybabtu)253 self.highlight("nav ul.navbar-nav", loops=3, scroll=False)254 self.highlight('nav a[href="/docs/"]', loops=1, scroll=False)255 self.highlight('nav a[href="/blog/"]', loops=1, scroll=False)256 self.highlight('nav a[href="/training/"]', loops=2, scroll=False)257 self.highlight('nav a[href="/partners/"]', loops=1, scroll=False)258 self.highlight('nav a[href="/community/"]', loops=1, scroll=False)259 self.highlight('nav a[href="/case-studies/"]', loops=1, scroll=False)260 self.highlight("nav #navbarDropdown", loops=2, scroll=False)261 if self.is_element_visible("h1"):262 self.highlight("h1", loops=6, scroll=False)263 self.open("https://www.selenium.dev/")264 if self.is_element_visible('button[data-dismiss="alert"] span'):265 self.js_click('button[data-dismiss="alert"] span', scroll=False)266 self.set_attributes("a.dropdown-toggle", "class", "nav-link")267 self.set_text_content('li a:contains("About")', "ALL")268 self.set_text_content('li a:contains("Downloads")', "YOUR")269 self.set_text_content('li a:contains("Documentation")', "BASE")270 self.set_text_content('li a:contains("Projects")', "ARE")271 self.set_text_content('li a:contains("Support")', "BELONG")272 self.set_text_content('li a:contains("Blog")', "TO")273 self.set_text_content('li a:contains("English")', "US")274 self.set_text_content("div.lead", aybabtu)275 self.set_text_content("h2", aybabtu)276 zoom_in = "div.lead{zoom: 1.25;-moz-transform: scale(1.25);}"277 self.add_css_style(zoom_in)278 self.highlight("div#main_navbar", loops=1, scroll=False)279 self.highlight('li a:contains("ALL")', loops=1, scroll=False)280 self.highlight('li a:contains("YOUR")', loops=1, scroll=False)281 self.highlight('li a:contains("BASE")', loops=2, scroll=False)282 self.highlight('li a:contains("ARE")', loops=1, scroll=False)283 self.highlight('li a:contains("BELONG")', loops=1, scroll=False)284 self.highlight('li a:contains("TO")', loops=1, scroll=False)285 self.highlight('li a:contains("US")', loops=2, scroll=False)286 self.highlight("div.lead", loops=6, scroll=False)287 self.highlight("h2", loops=8, scroll=False)288 self.open("https://www.python.org/")289 self.set_text_content('a[class="donate-button"]', ayb)290 self.set_text_content("#about a", "ALL")291 self.set_text_content("#downloads a", "YOUR")292 self.set_text_content("#documentation a", "BASE")293 self.set_text_content("#community a", "ARE")294 self.set_text_content("#success-stories a", "BELONG")295 self.set_text_content("#news a", "TO")296 self.set_text_content("#events a", "US")297 self.highlight('a[class="donate-button"]', loops=4, scroll=False)298 self.highlight("nav#mainnav", loops=5, scroll=False)299 self.highlight("#about a", loops=1, scroll=False)300 self.highlight("#downloads a", loops=1, scroll=False)301 self.highlight("#documentation a", loops=2, scroll=False)302 self.highlight("#community a", loops=1, scroll=False)303 self.highlight("#success-stories a", loops=1, scroll=False)304 self.highlight("#news a", loops=1, scroll=False)305 self.highlight("#events a", loops=2, scroll=False)306 self.open("https://docs.pytest.org/")307 self.set_text_content("h1", "pytest: " + aybabtu)308 self.highlight("h1", loops=10, scroll=False)309 self.open("https://wordpress.com/")310 self.set_text_content('a[title="Plans & Pricing"]', aybabtu)311 self.set_text_content('a[title="Get Started"]', ayb)312 self.set_text_content("p.no-widows", aybabtu)313 self.set_text_content("a#lpc-button", "Automate with SeleniumBase")314 self.highlight('a[title="Plans & Pricing"]', loops=6, scroll=False)315 self.highlight('a[title="Get Started"]', loops=4, scroll=False)316 self.highlight("p.no-widows", loops=8, scroll=False)317 self.highlight("a#lpc-button", loops=4, scroll=False)318 self.open("https://seleniumbase.com/")319 self.set_text_content("h1", aybabtu)320 self.highlight("h1", loops=10, scroll=False)321 self.open("https://pypi.org/")322 self.set_text_content('a[href="/sponsors/"]', aybabtu)323 self.set_text_content("h1", aybabtu)324 self.set_value("input#search", aybabtu, scroll=False)325 self.highlight('a[href="/sponsors/"]', loops=6, scroll=False)326 self.highlight("h1", loops=6, scroll=False)327 self.highlight("input#search", loops=8, scroll=False)328 self.open("https://www.atlassian.com/software/jira")329 self.set_text_content('a[href*="jira/pricing"]', ayb)330 self.set_text_content('a[href*="jira/enterprise"]', abtu)331 self.set_text_content('a[href="/software/jira/features"]', "")332 self.set_text_content('a[href="/software/jira/guides"]', "")333 self.set_text_content("h1", aybabtu)334 self.highlight("ul.imkt-navbar__link-list", loops=2, scroll=False)335 self.highlight('a[href*="jira/pricing"]', loops=3, scroll=False)336 self.highlight('a[href*="jira/enterprise"]', loops=3, scroll=False)337 self.highlight("h1", loops=6, scroll=False)338 self.open("https://status.iboss.com/ibcloud/app/cloudStatus.html")339 self.set_text_content('div[translate*="cloudStatus"]', ayb)340 self.set_text_content('div[translate*="maintenance"]', "ARE")341 self.set_text_content('div[translate*="advisory"]', "BELONG")342 self.set_text_content('div[translate*="incident"]', "TO US")343 self.set_text_content("h1", "Cloud Status - " + aybabtu)344 self.highlight("nav div.ibcloud-header-contents", loops=3)345 self.highlight('div[translate*="cloudStatus"]', loops=4)346 self.highlight('div[translate*="maintenance"]', loops=1)347 self.highlight('div[translate*="advisory"]', loops=1)348 self.highlight('div[translate*="incident"]', loops=3)349 self.highlight("h1", loops=9, scroll=False)350 self.open("https://git-scm.com/")351 self.set_text_content("span#tagline", aybabtu)352 self.set_text_content("#nav-about h3", ayb)353 self.set_text_content("#nav-documentation h3", abtu)354 self.highlight("span#tagline", loops=8, scroll=False)355 self.highlight("#nav-about h3", loops=5, scroll=False)356 self.highlight("#nav-documentation h3", loops=6, scroll=False)357 self.open("https://teamtreehouse.com/teams")358 self.set_text_content("li.nav-item-free-trial", aybabtu)359 self.set_text_content("h1", aybabtu)360 self.set_text_content("h2", aybabtu)361 self.set_text_content("p.homepage-signup-form-banner", aybabtu)362 self.highlight("li.nav-item-free-trial", loops=6, scroll=False)363 self.highlight("h1", loops=6, scroll=False)364 self.highlight('p[class*="signup-form"]', loops=6, scroll=False)365 self.open("https://pragprog.com/")366 self.set_text_content("header p", aybabtu)367 zoom_in = "header p{zoom: 1.35;-moz-transform: scale(1.35);}"368 self.add_css_style(zoom_in)369 self.highlight("header p", loops=10, scroll=False)370 self.open("https://seleniumbase.io/")371 self.set_text_content("h1", aybabtu)...
pages.py
Source:pages.py
...123 retv = True124 return retv125 def get_params(self):126 return127 def add_css_style(self):128 return129 def add_body_JS(self):130 return131 def add_content(self):132 self.get_params()133 return134 def create_page_html(self):135 self.add_css_style()136 self.add_body_JS()137 self.add_content()138 html = self.pageHtml % (self.title, self.css, self.bodyJS, self.content)139 return html140class AmbaVideoPage(AmbaPage):141 ''' This is Ambarella IPCAM Live Vide Page '''142 contentHtml = '''143 <div id="sitename" class="setting">144 <div id="title"></div>145 </div>146 <div id="wrap">147 <div id="content">%s</div>148 <div class="clearingdiv"> </div>149 </div>'''150 cssStyle = '''151 #container, #top { width:1280px; }152 #content { margin:0px; border-left:0px; border-right:0px; padding-left:0px; padding-right:0px }153 #display { width:100%; height:780px; align:center; padding:0px; }154 #video { margin:10px 0px 0px 0px; align:center;padding:0px; width:1280px; height:760px; position:absolute;display:block;overflow:auto}155 #videoforIE { margin:10px 0px 0px 0px;align:center;padding:0px;width:1280px;height:760px;position:absolute;display:block}156 #action { margin:10px; width:100%; height:60px; align:left;}157 .nav, .but { margin:3px; padding:5px; width:60px; vertical-align:middle; text-align:center; display:inline; text-transform:capitalize; }158 .but { width:auto; font-weight:bold; text-decoration:none; position:relative; }159 .textbox { width:10%; text-align:center; }160 .textinput { width:40px; }161 .right { float:right; }162 '''163 liveHtml = '''%s\n164 <div id="display">165 <div id="video">166 <OBJECT CLASSID="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" WIDTH=%d HEIGHT=%d style="margin:%dpx %dpx %dpx %dpx" align="absmiddle" ID="vlc" events="True">167 <param name="MRL" value="" >168 <param name="ShowDisplay" value="True" >169 <param name="AutoLoop" value="False" >170 <param name="AutoPlay" value="False" >171 <param name="Volume" value="50" >172 <param name="toolbar" value="true" >173 <param name="StartTime" value="0" >174 <EMBED pluginspage="http://www.videolan.org"175 type="application/x-vlc-plugin"176 version="VideoLAN.VLCPlugin.2"177 width="%d"178 height="%d"179 style="margin:%d 0 %d 0"180 toolbar="true"181 text="Waiting for video"182 name="vlc">183 </EMBED>184 </OBJECT>185 </div>186 '''187 liveHtmlforIE = '''\n188 <div id="videoforIE">189 <OBJECT CLASSID="CLSID:3BCDAA6A-7306-42FF-B8CF-BE5D3534C1E4" codebase="http://%s/activeX/ambaWeb.cab#version=%s" WIDTH=1280 HEIGHT=760 align="absmiddle" ID="AmbaIPCmrWebPlugIn1">190 <PARAM NAME="_Version" VALUE="65536">191 <PARAM NAME="_ExtentX" VALUE="19045">192 <PARAM NAME="_ExtentY" VALUE="11478">193 <PARAM NAME="_StockProps" VALUE="0">194 </OBJECT>195 </div>196 </div>197 <div id="action">\n%s198 </div>199 '''200 def __init__(self, name):201 super(AmbaVideoPage, self).__init__(name)202 self.title = 'Ambarella IPCAM Live View'203 self.width = 0204 self.height = 0205 return206 def create_button(self, name, value, exprop, action):207 text = ' <input class="but" id="%s" type="button" value="%s" %s onclick="javascript:%s"/>\n' \208 % (name, value, exprop, action)209 return text210 def create_select_label(self, label, name, options, value, action=''):211 text = '''<label for="%s">%s</label><select id="%s" onkeydown="javascript:%s">\n''' % (name, label, name, action)212 for item in options:213 sel = [' ', ' selected'][item[0] == value]214 text += '<option value=%d%s>%s</option>\n' % (item[0], sel, item[1])215 text += '</select>\n'216 return text217 def create_text_entry(self, label, name, value, maxlen, action):218 text = ' <label for="%s">%s</label>\n' % (name, label)219 text += '<input type="text" class="textinput" id="%s" value="%s" maxlength=%d onkeypress="javascript:NumOnly()" onkeydown="javascript:%s" />\n' \220 % (name, value, maxlen, action) 221 return text222 def add_settings(self):223 return224 def add_controls(self):225 return226 def add_css_style(self):227 super(AmbaVideoPage, self).add_css_style()228 self.css += self.cssStyle229 return230 def add_body_JS(self):231 # self.bodyJS = ''' onload="javascript: " ''' \232 return233 def process_PostData(self):234 ret = 0235 fieldform = cgi.FieldStorage()236 if len(fieldform) == 0 :237 return ret238 req_cnt = 0239 if fieldform.getvalue('req_cnt'):240 req_cnt = int(fieldform.getvalue('req_cnt'));241 for i in range (0, req_cnt):242 req = 'req%d' % i243 info = 'info%d' % i244 data = 'data%d' % i245 req_value = fieldform.getvalue(req)246 info_value = int(fieldform.getvalue(info))247 data_value = int(fieldform.getvalue(data))248 if req_value and (info_value or data_value):249 ret = self.trans.send_fly_request(req_value, info_value, data_value)250 if ret != 0 :251 return -1252 else :253 ret = -1254 break255 return req_cnt256 def add_content(self):257 super(AmbaVideoPage, self).add_content()258 settingText = self.add_settings()259 controlText = self.add_controls()260 if (self.width <= 1280) & (self.height <= 720):261 self.content = self.contentHtml % (self.liveHtml % (settingText, \262 self.width, self.height, (760-self.height)/2, (1280-self.width)/2, (760-self.height)/2, (1280-self.width)/2,\263 self.width, self.height, (760-self.height)/2, (760-self.height)/2\264 )+self.liveHtmlforIE % (self.host, self.version, controlText))265 else:266 self.content = self.contentHtml % (self.liveHtml % (settingText, 1280, 720, 20, 0, 20, 0, 1280, 720, 20, 20)+self.liveHtmlforIE % (self.host, self.version, controlText))267 return268class AmbaLiveViewPage(AmbaVideoPage):269 ''' This page is Privacy Mask page '''270 def __init__(self, streamId = 0, statSize = 0):271 super(AmbaLiveViewPage, self).__init__('liveview')272 self.title = 'Ambarella IPCAM Live View'273 self.streamId = streamId274 self.statSize = statSize275 self.create_params()276 return277 def create_params(self):278 self.live_params = {}279 self.live_params['encode_type'] = 0280 self.live_params['encode_fps'] = 30281 self.live_params['encode_width'] = 1280282 self.live_params['encode_height'] = 720283 self.live_params['brc_mode'] = 0284 self.live_params['cbr_avg_bps'] = 4000000285 self.live_params['vbr_min_bps'] = 1000000286 self.live_params['vbr_max_bps'] = 6000000287 return288 def get_params(self):289 ret = self.process_PostData()290 if ret < 0:291 print "1:set params failed"292 elif ret > 0:293 print "0:set params succeeded"294 elif ret == 0:295 return self.get_section_param('LIVE', self.live_params, self.streamId)296 else :297 print "1:unexpected error %d" % ret298 return 0299 def add_stream_resolution(self):300 self.width = self.live_params['encode_width']301 self.height = self.live_params['encode_height']302 return303 def add_settings(self):304 self.add_stream_resolution()305 text = ''306 text += ' <a class="nav" href="/cgi-bin/webdemo.cgi?page=enc">Setting</a>\n'307 text += ' <a class="nav" href="/cgi-bin/help.cgi?topic=live_view" target="_blank" >Help</a>\n'308 text += ' <label>Live Stream '309 for item in range(len(NUM)):310 sel = ['', ' active'][item == self.streamId]311 text += '''<a class="nav%s" href="/cgi-bin/live_view.cgi?streamId=%d">%s</a>\n''' \312 % (sel, item, NUM[item])313 text += '</label>\n'314 text += ' '315 text += ' <input class="but" id="z" type="button" value="Z" style="visibility:hidden" />\n'316 #text += self.create_button('Stat', 'Hide Statistics', '', "ShowStat()")317 #text += ' '318 #text += self.create_button('DPTZ', 'Hide Digital PTZ', 'hidden', "ShowDPTZ()") + '<br>\n'319 return text320 def add_controls(self):321 text = ''322 text += self.create_button('Play', 'Play', '', "PlayVideo()")323 text += self.create_button('Stop', 'Stop', '', "StopVideo()")324 text += self.create_button('Record', 'Start Record', '', "Record()")325 text += self.create_button('ForceIdr', 'Force Idr', '', \326 "FlySet(%d, 'ForceIdr')" % (self.streamId))327 options = []328 fpsList = [60, 30, 25, 20, 15, 10, 6, 5, 4, 3, 2, 1]329 for item in fpsList:330 item = '%s' % item331 options.append([PP.fps[item], item])332 text += self.create_select_label('Encode frame rate (1~30) :', 'ChangeFr', options, \333 self.live_params['encode_fps'], "FlySet(%d, 'ChangeFr')" % (self.streamId))334 if self.live_params['encode_type'] == 1: # H264335 options = [[PP.brc['cbr'], 'CBR'], [PP.brc['vbr'], 'VBR'], \336 [PP.brc['cbrq'], 'CBR (keep quality)'], \337 [PP.brc['vbrq'], 'VBR (keep quality)']]338# text += self.create_select_label("BRC:", "ChangeBRC", options, \339# self.live_params['brc_mode'], "FlySet(%d, 'ChangeBRC')" % (self.streamId))340 if self.live_params['brc_mode'] & 0x1 :341 text += self.create_text_entry('VBR min bitrate(kbps) :', 'ChangeVBRMinBps', \342 self.live_params['vbr_min_bps'] / 1000, 5, \343 "FlySet(%d, 'ChangeVBRMinBps')" % (self.streamId))344 text += self.create_text_entry('VBR max bitrate(kbps) :', 'ChangeVBRMaxBps', \345 self.live_params['vbr_max_bps'] / 1000, 5, \346 "FlySet(%d, 'ChangeVBRMaxBps')" % (self.streamId))347 else :348 text += self.create_text_entry('CBR average bitrate(kbps) :', 'ChangeCBRAvgBps', \349 self.live_params['cbr_avg_bps'] / 1000, 5, \350 "FlySet(%d, 'ChangeCBRAvgBps')" % (self.streamId))351# text += self.create_button('Apply', 'Apply', '', "ApplyFlySetting(%d)" % (self.streamId))352 return text353 def add_body_JS(self):354 self.bodyJS = ''' onload="javascript: OnLoadActiveX('%s', %d, %d, %d, %d);" ''' % \355 (self.host, self.streamId, self.recvType, self.statSize, 1)356 #self.bodyJS += ''' onload="javascript: OnClose();" '''357 return358 def show_page(self):359 print self.create_page_html()360 return361class AmbaConfigPage(AmbaPage):362 ''' This is Ambarella IPCAM Config Page '''363 contentHtml = '''364 <div id="sitename" class="setting">365 <div id="title"></div>366 </div>367 <div id="wrap">368 <div id="menunav"><p>369 %s</p>370 <p> </p>371 </div>372 <div id="content">373 <div id="status"> </div>374 %s375 </div>376 <div class="clearingdiv"> </div>377 </div>378 '''379 cssStyle = '''380 #container, #top { width:800px; }381 #content { margin:0 20px 0 200px; }382 '''383 menuMap = {}384 pageMap = {}385 def __init__(self, name, activeMenu, activeSubMenu = None):386 super(AmbaConfigPage, self).__init__(name)387 self.title = 'Ambarella IPCAM Setting'388 self.activeMenu = activeMenu389 self.activeSubMenu = activeSubMenu390 self.add_menu_info()391 self.add_page_info()392 return393 def add_menu_info(self):394 if self.menuMap.has_key(self.activeMenu):395 subMenu = self.menuMap[self.activeMenu]396 else:397 subMenu = []398 if self.activeSubMenu and \399 self.activeSubMenu not in subMenu:400 subMenu.append(self.activeSubMenu)401 self.menuMap[self.activeMenu] = subMenu402 return403 def get_page_key(self, menu, subMenu = None):404 if subMenu:405 key = '%s/%s' % (menu, subMenu)406 else:407 key = menu408 return key409 def add_page_info(self):410 pageKey = self.get_page_key(self.activeMenu, self.activeSubMenu)411 if not self.pageMap.has_key(pageKey):412 self.pageMap[pageKey] = self.name413 return414 def create_menu_item(self, page, menuName, status = None):415 if status:416 menuType = ' %s' % status417 else:418 menuType = ''419 line = ' <a class="nav%s" href="%s?page=%s">%s</a><span class="hide"> | </span>\n' \420 % (menuType, self.pageURL, page, menuName)421 return line422 def create_sub_menu(self):423 subMenuString = ''424 if len(self.menuMap[self.activeMenu]) > 0:425 for sub in self.menuMap[self.activeMenu]:426 status = 'sub' + ['', ' active'][sub == self.activeSubMenu]427 pageKey = self.get_page_key(self.activeMenu, sub)428 page = self.pageMap[pageKey]429 subMenuString += self.create_menu_item(page, sub, status)430 return subMenuString431 def create_live_menu(self):432 menuString = '<a class="nav">Live View</a><span class="hide"> | </span>\n'433 for i in range(len(NUM)):434 menuString += ' <a class="nav sub active" href="/cgi-bin/live_view.cgi?streamId=%d">' \435 % (i)436 menuString += '%s</a><span class="hide"> | </span>\n' % NUM[i]437 return menuString438 def create_menu(self):439 menuString = self.create_live_menu()440 for name in sorted(self.menuMap.keys()):441 isActive = [False, True][name == self.activeMenu]442 if len(self.menuMap[name]) > 0:443 sub = self.menuMap[name][0]444 else:445 sub = None446 pageKey = self.get_page_key(name, sub)447 page = self.pageMap[pageKey]448 if isActive:449 menuString += self.create_menu_item(page, name, 'active')450 menuString += self.create_sub_menu()451 else:452 menuString += self.create_menu_item(page, name)453 self.menu = menuString454 return menuString455 def support_cgi(self):456 print self.header # HTML is following457 print458 return459 def add_params(self):460 return ''461 def show_params(self):462 if self.get_params() != 1:463 return464 print '<div id="status"> </div>\n'465 print self.add_params()466 return467 def create_slider_bar(self, label, name, value, sliderRange, outBox):468 smin, smax = sliderRange469 width = smax - smin470 SLIDERWIDTH = 350471 left = (value - smin) * SLIDERWIDTH / width472 text = ' <label>%s:</label>\n' % label473 action = '''<input type="text" class="textinput" id="%s" value="%s" maxlength=%d readonly="readonly" />''' % (outBox, value, 4)474 text += ''' %s''' % action + '<br><br>\n'475 text += ' <div class="left barholder"></div>\n'476 action = '''onclick="javascript:AddSubOneStep('%s', '%s', %d, %d, 1)"''' % (name, outBox, width, smin)477 text += ' <div class="left"><img src="../img/left.gif" %s />%d </div>\n' % (action, smin)478 action = '''onmouseover="javascript:MoveBar('%s', '%s', %d, %d)"''' % (name, outBox, width, smin)479 text += ' <div class="left slider">'480 text += '<div class="bar" id="%s" %s style="left: %dpx; "></div></div>\n' % (name, action, left)481 action = '''onclick="javascript:AddSubOneStep('%s', '%s', %d, %d, 0)"''' % (name, outBox, width, smin)482 text += ' <div class="left"> %d<img src="../img/right.gif" %s /></div>\n' % (smax, action)483 return text484 def process_PostData(self):485 fieldform = cgi.FieldStorage()486 if fieldform.getvalue('req_cnt'):487 req_cnt = int(fieldform.getvalue('req_cnt'));488 for i in range (0, req_cnt):489 sec = 'sec%d' % i490 data = 'data%d' % i491 sec_value = fieldform.getvalue(sec)492 data_value = fieldform.getvalue(data)493 if sec_value and data_value :494 if (self.trans.send_set_request('REQ_SET_PARAM', sec_value, data_value)) != 0 :495 return -1496 else :497 return -1498 return 0499 else :500 return 1501 ''' These methods inherited from AmbaPage base class '''502 def add_css_style(self):503 super(AmbaConfigPage, self).add_css_style()504 self.css += self.cssStyle505 return506 def add_body_JS(self):507 self.bodyJS = ''' onload="javascript: getData('%s')" ''' \508 % (self.name)509 return510 def add_content(self):511 super(AmbaConfigPage, self).add_content()512 menu = self.create_menu()513 params = self.add_params()514 self.content += self.contentHtml % (menu, params)515 return516 ''' This is auto test method '''517 def auto_test(self):...
upload_file_test.py
Source:upload_file_test.py
...5 def test_file_upload_button(self):6 self.open("https://seleniumbase.io/w3schools/file_upload")7 self.switch_to_frame("iframeResult")8 zoom_in = 'input[type="file"]{zoom: 1.6;-moz-transform: scale(1.6);}'9 self.add_css_style(zoom_in)10 self.highlight('input[type="file"]')11 dir_name = os.path.dirname(os.path.abspath(__file__))12 my_file = "screenshot.png"13 file_path = os.path.join(dir_name, "example_logs/%s" % my_file)14 self.assert_attribute("#myFile", "value", "")15 self.choose_file('input[type="file"]', file_path)16 self.assert_attribute("#myFile", "value", "C:\\fakepath\\%s" % my_file)...
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!!