Best Python code snippet using pyatom_python
driver.py
Source:driver.py
1try:2 import selenium3except ImportError:4 raise ImportError("As root Install python-selenium by running: 'pip install selenium'")5import os6import time7import express8from frlog import LOG9from selenium import webdriver10from selenium.common.exceptions import WebDriverException11from selenium.webdriver.common.desired_capabilities import DesiredCapabilities12class Driver(object):13 """14 Wrapper for Selenium Remote WebDriver class.15 """16 def __init__(self, driverHostname, driverPort, browser, maximizeWindow=True):17 """18 @param driverHostname: Host name on which instance of Remote WebDriver is running.19 Ex. 'mvm-win35'20 @param driverPort: Port number which WebDriver is communicating over. Ex. 444421 @param browser: Type of browser which is open by WebDriver: 'firefox' or 'chrome'.22 @param maximizeWindow: If True (default), maximize newly opened window in browser.23 """24 LOG.info('Instantiating Mangal.Driver...')25 self.driverHostname = driverHostname26 self.driverPort = driverPort27 self.browser = browser28 self.timeout = 1029 self.delay = .330 self._maximizeWindow = maximizeWindow31 self._start()32 def _start(self):33 self.capabilities = None34 if self.browser == 'firefox':35 self.capabilities = DesiredCapabilities.FIREFOX.copy()36 elif self.browser == 'chrome':37 self.capabilities = DesiredCapabilities.CHROME.copy()38 else:39 raise FailedConfigException('Unsupported type of browser:', browser)40 self.webDriver = webdriver.Remote(command_executor='http://%s:%s/wd/hub' %41 (self.driverHostname, self.driverPort), desired_capabilities=self.capabilities)42 if self._maximizeWindow:43 self.maximizeWindow()44 def getWebDriver(self):45 return self.webDriver46 def forward(self):47 LOG.l4('Navigating forward in browser history')48 self.webDriver.forward()49 def back(self):50 LOG.l4('Navigating back in browser history')51 self.webDriver.back()52 def close(self):53 LOG.l4('Closing browser active window')54 try:55 self.webDriver.close()56 except WebDriverException, e:57 LOG.l4('WebDriver.close():', e.msg)58 def quit(self):59 LOG.l4('Quitting WebDriver')60 try:61 self.webDriver.quit()62 except WebDriverException, e:63 LOG.l4('WebDriver.quit():', e.msg)64 def maximizeWindow(self):65 """66 Maximize browser's active window67 """68 self.webDriver.maximize_window()69 def takeScreenshot(self, name):70 """71 Save screenshot of active web page to PNG file.72 @param name: Name of screenshot file.73 """74 if LOG.getLogDir() is not None:75 logDirectory = LOG.getLogDir()76 else:77 logDirectory = os.getcwd()78 pathFileName = os.path.join(logDirectory, name + '.' +79 express.getUnixTime(formatstr='%Y%m%d_%H%M%S') + '.png')80 self.webDriver.save_screenshot(pathFileName)81 LOG.l4("Mangal.Driver: takeScreenshot(): Saved into '%s'" % pathFileName)82 def setBrowser(self, browser):...
title_bar.py
Source:title_bar.py
1from qt_core import *2from builder.template_app.gui.content import *3from builder.template_app.gui.functions.settings import Settings4from builder.template_app.gui.functions.ui_functions import UIFunctions5class TitleBar(QWidget):6 def __init__(self, parent=None):7 super(self.__class__, self).__init__(parent)8 #self.setupUi(self)9 self.ui = parent10 settings = Settings('ui')11 self.settings = settings.items12 settings = Settings('theme')13 self.theme_settings = settings.items14 #self.icon = QIcon()15 self.icon_color = self.theme_settings['theme']['titlebar']['icons']16 17 self.ui.appTitle.setText(self.settings['window']['app_name'])18 self.ui.appDescription.setText(self.settings['window']['description'])19 self.ui.appLogo.setPixmap(QPixmap(UIFunctions().resource_path(self.settings['window']['icon'])))20 21 if not self.settings['window']['frameless']:22 self.ui.windowicons.hide()23 else:24 icon = qta.icon("msc.chrome-maximize", color=self.icon_color)25 self.ui.maximizewindow.setIcon(icon)26 icon = qta.icon("msc.chrome-close", color=self.icon_color)27 self.ui.closewindow.setIcon(icon)28 icon = qta.icon("msc.chrome-minimize", color=self.icon_color)29 self.ui.minimizewindow.setIcon(icon)30 31 32 self.ui.maximizewindow.clicked.connect(self.icon_maximize_restore) 33 self.ui.minimizewindow.clicked.connect(self.ui.window().showMinimized)34 self.ui.closewindow.clicked.connect(self.ui.window().close)35 self.ui.appDescription.mouseDoubleClickEvent = self.dbclick_maximize_restore36 def icon_maximize_restore(self):37 self.ui.window().showMaximized38 button = self.sender()39 40 if self.ui.window().isMaximized():41 icon = qta.icon("msc.chrome-maximize", color=self.icon_color)42 button.setIcon(icon)43 self.ui.window().showNormal()44 else:45 icon = qta.icon("msc.chrome-restore", color=self.icon_color)46 button.setIcon(icon)47 self.ui.window().showMaximized()48 49 def dbclick_maximize_restore(self, event=None):50 if self.settings['window']['frameless']:51 QTimer.singleShot(0, self.ui.maximizewindow.clicked.emit)...
006_maximizeWindow.py
Source:006_maximizeWindow.py
1# -*- coding: utf-8 -*-2# ***************************************************3# @Test Case ID: 006_maximizeWindow4# @Test Description: MaximizeWindow(win uint32),æ大åç»å®idççªå£å®ä¾ï¼é¦å
ä¼è°ç¨ActivateWindowæ¿æ´»çªå£å使ä¹æ大å5# win: 请åèActivateWindowå½æ°çwinåæ°6# @Test Condition: 1.æå¼ä¸ä¸ªæ件管çå¨çªå£7# 2.è·åæ件管çå¨ççªå£id8# @Test Step: 1.è°ç¨ MaximizeWindow å½æ°,ä¼ å
¥æ件管çå¨ççªå£id9# @Test Result: 1.ç¨åºæ æ¥é10# @Test Remark:11# @Author: ut00162712# ***************************************************13import time14import subprocess15import pytest16from frame.base import OSBase17from aw.dbus.sessionBus import dock18class TestCase(OSBase):19 def setUp(self):20 self.Step("é¢å¶æ¡ä»¶1:æå¼ä¸ä¸ªæ件管çå¨çªå£")21 self.p = subprocess.Popen('dde-file-manager')22 time.sleep(5)23 self.win_id = dock.get_window_id_by_name()24 time.sleep(1)25 @pytest.mark.public26 def test_step(self):27 self.Step("æ¥éª¤1:è°ç¨ MaximizeWindow å½æ°,ä¼ å
¥æ件管çå¨ççªå£id")28 dock.maximizeWindow(self.win_id)29 def tearDown(self):30 self.Step("æ¶å°¾:å
³éæ件管çå¨åè¿ç¨")31 self.p.kill()...
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!!