How to use screenLocked method in fMBT

Best Python code snippet using fMBT_python

PowerStatus.py

Source:PowerStatus.py Github

copy

Full Screen

1from poshc2.server.database.DB import get_powerstatusbyrandomuri, insert_blankpowerstatus, update_screenlocked, update_monitoron2from poshc2.server.database.DB import update_powerstatus, update_acstatus, update_apmstatus3def create_if_no_status_for_uri(RandomURI):4 result = get_powerstatusbyrandomuri(RandomURI)5 if result is None:6 insert_blankpowerstatus(RandomURI)7def translate_power_status(status, RandomURI):8 if "Power Status Monitoring:" in status:9 print(status)10 elif ":" in status:11 create_if_no_status_for_uri(RandomURI)12 splt = status.split(":")13 if splt[0] == "WM_QUERYENDSESSION":14 print("[!] SHUTDOWN may be imminent. Query End Session has been called:")15 elif splt[0] == "WM_WTSSESSION_CHANGE":16 if splt[1] == "CONSOLE_CONNECT":17 print("[+] Console session has been connected to")18 elif splt[1] == "CONSOLE_DISCONNECT":19 print("[-]Console session has been disconnected from ")20 elif splt[1] == "REMOTE_CONNECT":21 print("[+] Remote connection has been made to the machine (RDP)")22 elif splt[1] == "REMOTE_DISCONNECT":23 print("[-] Remote connection has been dropped (RDP)")24 elif splt[1] == "SESSION_LOGON":25 print("[+] A user has logged on")26 elif splt[1] == "SESSION_LOGOFF":27 print("[!] A user has logged off")28 elif splt[1] == "SESSION_LOCK":29 print("[!] Session has been locked")30 update_screenlocked(RandomURI, 1)31 elif splt[1] == "SESSION_UNLOCK":32 print("[+] Session has been unlocked")33 update_screenlocked(RandomURI, 0)34 elif splt[1] == "SESSION_REMOTE_CONTROL":35 print("[-] Session remote control status has changed")36 elif splt[0] == "WM_POWERBROADCAST":37 if splt[1] == "GUID_MONITOR_POWER_ON":38 if splt[2] == "On":39 update_monitoron(RandomURI, 1)40 print("[+] Monitor(screen) has been switched ON")41 else:42 update_monitoron(RandomURI, 0)43 print("[!] Monitor(screen) has been switched OFF")44 elif splt[1] == "GUID_BATTERY_PERCENTAGE_REMAINING":45 result = get_powerstatusbyrandomuri(RandomURI)46 if (splt[2].isdigit()):47 battperc = int(splt[2])48 if (battperc <= 100 and battperc >= 0):49 if (battperc > 50):50 print("[+] Battery has %s%% charge" % battperc)51 elif battperc > 15:52 print("[!] WARNING: Battery has only %s%% charge" % battperc)53 elif battperc < 15:54 print("[!] CRITICAL BATTERY: %s%% charge left" % battperc)55 update_powerstatus(RandomURI, result[3], result[4], result[5], ("%s%%" % battperc))56 else:57 print("[-] Battery status: UNKNOWN")58 update_powerstatus(RandomURI, result[3], result[4], result[5], "UNKNOWN")59 elif splt[1] == "GUID_ACDC_POWER_SOURCE":60 if splt[2] == "Unplugged":61 update_acstatus(RandomURI, 0)62 print("[!] DISCHARGING the battery now. AC has been unplugged.")63 else:64 if splt[2] == "UPS":65 print("[!] UPS powered now. Machine may turn off at any time")66 update_acstatus(RandomURI, 0)67 elif splt[1] == "PBT_APMBATTERYLOW":68 print("[!] Low battery reported")69 result = get_powerstatusbyrandomuri(RandomURI)70 update_powerstatus(RandomURI, result[3], result[4], "LOW", result[6])71 elif splt[1] == "PBT_APMQUERYSUSPEND":72 print("[!] SUSPEND may be imminent. QuerySuspend has been called:")73 update_apmstatus(RandomURI, "QUERYSUSPEND")74 elif splt[1] == "PBT_APMSUSPEND":75 print("[!] SUSPEND/SLEEP, machine has been hibernated")76 update_apmstatus(RandomURI, "SUSPEND")77 elif splt[1] == "PBT_APMRESUMESUSPEND":78 print("[+] Resume from suspend.")79 update_apmstatus(RandomURI, "RESUME")80 elif splt[1] == "PBT_APMPOWERSTATUSCHANGE":81 lns = status.splitlines(False)82 result = get_powerstatusbyrandomuri(RandomURI)83 acpower = result[3]84 chrging = result[4]85 stus = result[5]86 percent = result[6]87 for i in lns:88 if i.startswith("GUID_ACDC_POWER_SOURCE:"):89 if(i[23:] == "Plugged"):90 print("[+] AC is plugged in")91 acpower = 192 elif (i[23:] == "Unplugged"):93 print("[!] AC has been unplugged")94 acpower = 095 elif (i[23:] == "UPS"):96 print("[!] Computer is on a UPS")97 acpower = 098 elif i.startswith("CHRG:"):99 chrging = (i[5:] == "CHARGING")100 print("[+] Battery is charging: %s" % chrging)101 elif i.startswith("PERCENT:"):102 prcnt = i[8:]103 if prcnt != "UNKNOWN" and prcnt.isdigit():104 percent = ("%s%%" % prcnt)105 print("[+] Battery Percent: %s" % percent)106 else:107 percent = "UNKNOWN"108 print("[-] Battery Percent: UNKNOWN")109 elif i.startswith("BATTERY:"):110 stus = i[8:]111 if stus is None or status == "":112 stus = "UNKNOWN"113 print("[-] Battery Status: UNKNOWN")114 else:115 print("[+] Battery Status: %s" % stus)116 update_powerstatus(RandomURI, acpower, chrging, stus, percent)117def getpowerstatus(randomuri):118 pwrStatus = get_powerstatusbyrandomuri(randomuri)119 if (pwrStatus is not None):120 if (pwrStatus[9] is not None and pwrStatus[9] != ""):121 print("[+] Power status @ %s" % pwrStatus[9])122 else:123 print("[+] Power status")124 if (pwrStatus[2] is not None and pwrStatus[2] != ""):125 print("apmstatus: %s" % pwrStatus[2])126 if (pwrStatus[3]):127 if (not pwrStatus[4]):128 print("BATTERY: Not Charging")129 else:130 print("BATTERY: Charging")131 else:132 print("BATTERY: Discharging %s%%" % pwrStatus["BatteryPercentLeft"])133 if (pwrStatus[5] is not None and pwrStatus[5] != ""):134 print("BATTERY FLAG: %s" % pwrStatus[5])135 if (pwrStatus[7] > 0):136 print("SCREEN: LOCKED")137 else:138 print("SCREEN: UNLOCKED")139 if (pwrStatus[8]):140 print("MONITOR: ON")141 else:142 print("MONITOR: OFF")143 else:...

Full Screen

Full Screen

cros_unittest.py

Source:cros_unittest.py Github

copy

Full Screen

1# Copyright 2014 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import logging5from telemetry import test6from telemetry.core import exceptions7from telemetry.core import util8from telemetry.core.backends.chrome import cros_test_case9class CrOSCryptohomeTest(cros_test_case.CrOSTestCase):10 @test.Enabled('chromeos')11 def testCryptohome(self):12 """Verifies cryptohome mount status for regular and guest user and when13 logged out"""14 with self._CreateBrowser() as b:15 self.assertEquals(1, len(b.tabs))16 self.assertTrue(b.tabs[0].url)17 self.assertTrue(self._IsCryptohomeMounted())18 # TODO(achuith): Remove dependency on /home/chronos/user.19 chronos_fs = self._cri.FilesystemMountedAt('/home/chronos/user')20 self.assertTrue(chronos_fs)21 if self._is_guest:22 self.assertEquals(chronos_fs, 'guestfs')23 else:24 crypto_fs = self._cri.FilesystemMountedAt(25 self._cri.CryptohomePath(self._username))26 self.assertEquals(crypto_fs, chronos_fs)27 self.assertFalse(self._IsCryptohomeMounted())28 self.assertEquals(self._cri.FilesystemMountedAt('/home/chronos/user'),29 '/dev/mapper/encstateful')30class CrOSLoginTest(cros_test_case.CrOSTestCase):31 @test.Enabled('chromeos')32 def testLoginStatus(self):33 """Tests autotestPrivate.loginStatus"""34 if self._is_guest:35 return36 with self._CreateBrowser(autotest_ext=True) as b:37 login_status = self._GetLoginStatus(b)38 self.assertEquals(type(login_status), dict)39 self.assertEquals(not self._is_guest, login_status['isRegularUser'])40 self.assertEquals(self._is_guest, login_status['isGuest'])41 self.assertEquals(login_status['email'], self._username)42 self.assertFalse(login_status['isScreenLocked'])43 @test.Enabled('chromeos')44 def testLogout(self):45 """Tests autotestPrivate.logout"""46 if self._is_guest:47 return48 with self._CreateBrowser(autotest_ext=True) as b:49 extension = self._GetAutotestExtension(b)50 try:51 extension.ExecuteJavaScript('chrome.autotestPrivate.logout();')52 except (exceptions.BrowserConnectionGoneException,53 exceptions.BrowserGoneException):54 pass55 util.WaitFor(lambda: not self._IsCryptohomeMounted(), 20)56 @test.Enabled('chromeos')57 def testGaiaLogin(self):58 """Tests gaia login. Credentials are expected to be found in a59 credentials.txt file, with a single line of format username:password."""60 if self._is_guest:61 return62 (username, password) = self._Credentials('credentials.txt')63 if username and password:64 with self._CreateBrowser(gaia_login=True,65 username=username,66 password=password):67 self.assertTrue(util.WaitFor(self._IsCryptohomeMounted, 10))68class CrOSScreenLockerTest(cros_test_case.CrOSTestCase):69 def _IsScreenLocked(self, browser):70 return self._GetLoginStatus(browser)['isScreenLocked']71 def _LockScreen(self, browser):72 self.assertFalse(self._IsScreenLocked(browser))73 extension = self._GetAutotestExtension(browser)74 self.assertTrue(extension.EvaluateJavaScript(75 "typeof chrome.autotestPrivate.lockScreen == 'function'"))76 logging.info('Locking screen')77 extension.ExecuteJavaScript('chrome.autotestPrivate.lockScreen();')78 logging.info('Waiting for the lock screen')79 def ScreenLocked():80 return (browser.oobe_exists and81 browser.oobe.EvaluateJavaScript("typeof Oobe == 'function'") and82 browser.oobe.EvaluateJavaScript(83 "typeof Oobe.authenticateForTesting == 'function'"))84 util.WaitFor(ScreenLocked, 10)85 self.assertTrue(self._IsScreenLocked(browser))86 def _AttemptUnlockBadPassword(self, browser):87 logging.info('Trying a bad password')88 def ErrorBubbleVisible():89 return not browser.oobe.EvaluateJavaScript('''90 document.getElementById('bubble').hidden91 ''')92 self.assertFalse(ErrorBubbleVisible())93 browser.oobe.ExecuteJavaScript('''94 Oobe.authenticateForTesting('%s', 'bad');95 ''' % self._username)96 util.WaitFor(ErrorBubbleVisible, 10)97 self.assertTrue(self._IsScreenLocked(browser))98 def _UnlockScreen(self, browser):99 logging.info('Unlocking')100 browser.oobe.ExecuteJavaScript('''101 Oobe.authenticateForTesting('%s', '%s');102 ''' % (self._username, self._password))103 util.WaitFor(lambda: not browser.oobe_exists, 10)104 self.assertFalse(self._IsScreenLocked(browser))105 @test.Enabled('chromeos')106 def testScreenLock(self):107 """Tests autotestPrivate.screenLock"""108 if self._is_guest:109 return110 with self._CreateBrowser(autotest_ext=True) as browser:111 self._LockScreen(browser)112 self._AttemptUnlockBadPassword(browser)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1# coding: utf-82"""3Base para desarrollo de modulos externos.4Para obtener el modulo/Funcion que se esta llamando:5 GetParams("module")6Para obtener las variables enviadas desde formulario/comando Rocketbot:7 var = GetParams(variable)8 Las "variable" se define en forms del archivo package.json9Para modificar la variable de Rocketbot:10 SetVar(Variable_Rocketbot, "dato")11Para obtener una variable de Rocketbot:12 var = GetVar(Variable_Rocketbot)13Para obtener la Opcion seleccionada:14 opcion = GetParams("option")15Para instalar librerias se debe ingresar por terminal a la carpeta "libs"16 17 pip install <package> -t .18"""19from subprocess import Popen, PIPE20import sys21import os22import platform23base_path = tmp_global_obj["basepath"]24cur_path = base_path + 'modules' + os.sep + 'screenLocked' + os.sep + 'libs' + os.sep25sys.path.append(cur_path)26import psutil27"""28 Obtengo el modulo que fue invocado29"""30module = GetParams("module")31if module == "screenLocked":32 var_ = GetParams('var_')33 process_name='LogonUI.exe'34 callall='TASKLIST'35 outputall=subprocess.check_output(callall)36 outputstringall=str(outputall)37 if process_name in outputstringall:38 print("Bloqueado.")39 SetVar(var_,True)40 else: 41 print("Desbloqueado.")42 SetVar(var_,False)43if module == "enableScreenLocked":44 try:45 for proc in psutil.process_iter():46 # check whether the process name matches47 if proc.name() == 'NoSleep2.0.exe':48 proc.kill()49 break50 except Exception as e:51 PrintException()52 raise e53if module == "disableScreenLocked":54 try:55 path = tmp_global_obj["basepath"]56 ejecutable = path + 'modules' + os.sep + 'screenLocked' + os.sep + 'bin' + os.sep + 'NoSleep2.0.exe'57 p = subprocess.Popen(ejecutable, shell=True, stdin=PIPE)58 except Exception as e:59 PrintException()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful