How to use klik method in SeleniumBase

Best Python code snippet using SeleniumBase

ir_whatsapp_server.py

Source:ir_whatsapp_server.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Part of Odoo. See LICENSE file for full copyright and licensing details.3from email import encoders4from email.charset import Charset5from email.header import Header6from email.mime.base import MIMEBase7from email.mime.multipart import MIMEMultipart8from email.mime.text import MIMEText9from email.utils import COMMASPACE, formataddr, formatdate, getaddresses, make_msgid10import logging11import re12import smtplib13import json14import threading15from ..klikapi import KlikApi16import html2text17from odoo import api, fields, models, tools, _, sql_db18from odoo.exceptions import except_orm, UserError19from odoo.tools import ustr, pycompat20_logger = logging.getLogger(__name__)21SMTP_TIMEOUT = 6022class IrWhatsappServer(models.Model):23 """Represents an SMTP server, able to send outgoing emails, with SSL and TLS capabilities."""24 _name = "ir.whatsapp_server"25 _description = 'Whatsapp Server'26 name = fields.Char(string='Description', required=True, index=True)27 sequence = fields.Integer(string='Priority', default=10, help="When no specific mail server is requested for a mail, the highest priority one "28 "is used. Default priority is 10 (smaller number = higher priority)")29 active = fields.Boolean(default=True)30 klik_key = fields.Char("KlikApi Key", help="Optional key for SMTP authentication")31 klik_secret = fields.Char("KlikApi Secret", help="Optional secret for SMTP authentication")32 qr_scan = fields.Binary("QR Scan")33 status = fields.Selection([('init','Initial Status'),34 ('loading', 'Loading'),35 ('got qr code', 'QR Code'),36 ('authenticated', 'Authenticated')], default='init', string="Status")37 hint = fields.Char(string='Hint', readonly=True, default="Configure Token and Instance")38 message_ids = fields.One2many('mail.message', 'whatsapp_server_id', string="Mail Message") 39 message_counts = fields.Integer('Message Sent Counts', compute='_get_mail_message_whatsapp')40 notes = fields.Text(readonly=True)41 42 def _get_mail_message_whatsapp(self):43 KlikApi = self.klikapi()44 KlikApi.auth()45 data = KlikApi.get_count()46 self.message_counts = data47 48 def _formatting_mobile_number(self, number):49 for rec in self:50 module_rec = self.env['ir.module.module'].sudo().search_count([51 ('name', '=', 'crm_phone_validation'),52 ('state', '=', 'installed')])53 return module_rec and re.sub("[^0-9]", '', number) or \54 str(rec.partner_id.country_id.phone_code55 ) + number56 def klikapi(self):57 return KlikApi(self.klik_key, self.klik_secret)58 59 def klikapi_status(self):60 #WhatsApp is open on another computer or browser. Click “Use Here” to use WhatsApp in this window.61 data = {}62 KlikApi = self.klikapi()63 KlikApi.auth()64 data = KlikApi.get_request(method='status', data=data)65 # print ('---data---',data)66 if data.get('accountStatus') == 'loading':67 self.hint = 'Auth status is Loading! Please click QR Code/Use here again'68 self.status = 'loading'69 self.notes = ''70 elif data.get('accountStatus') == 'authenticated':71 #ALREADY SCANNED72 self.hint = 'Auth status Authenticated'73 self.status = 'authenticated'74 self.notes = ''75 elif data.get('qrCode'):76 #FIRST SCANNED OR RELOAD QR77 #print('33333')78 qrCode = data.get('qrCode').split(',')[1]79 self.qr_scan = qrCode80 self.status = 'got qr code'81 self.hint = 'To send messages, you have to authorise like for WhatsApp Web'82 self.notes = """1. Open the WhatsApp app on your phone832. Press Settings->WhatsApp WEB and then plus843. Scan a code and wait a minute854. Keep your phone turned on and connected to the Internet86A QR code is valid only for 45 seconds. Message sennding will be available right after authorization."""87 else:88 #print('44444')89 #ERROR GET QR90 self.qr_scan = False91 self.status = 'init'92 self.hint = data.get('error')93 self.notes = ''94 95 def klikapi_logout(self):96 KlikApi = self.klikapi()97 KlikApi.auth()98 KlikApi.logout()99 self.write({'qr_scan': False, 'hint': 'Logout Success', 'notes': '', 'status': 'init'})100 101 102 def redirect_whatsapp_key(self):103 return {104 'type': 'ir.actions.act_url',105 'url': 'https://klikodoo.id/shop/product/whatsapp-api-14',106 'target': '_new',107 }108 109 @api.model110 def _send_whatsapp(self, numbers, message):111 """ Send whatsapp """112 KlikApi = self.klikapi()113 KlikApi.auth()114 new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()115 for number in numbers:116 whatsapp = self._formatting_mobile_number(number)117 message_data = {118 'phone': whatsapp,119 'body': html2text.html2text(message),120 }121 data_message = json.dumps(message_data)122 send_message = KlikApi.post_request(method='sendMessage', data=data_message)123 if send_message.get('message')['sent']:124 _logger.warning('Success to send Message to WhatsApp number %s', whatsapp)125 else:126 _logger.warning('Failed to send Message to WhatsApp number %s', whatsapp)127 new_cr.commit()...

Full Screen

Full Screen

api.py

Source:api.py Github

copy

Full Screen

1from odoo import _2from odoo.exceptions import Warning, UserError3from odoo.http import request, Response4import json5import requests6import html2text7import datetime8class KlikApi(object):9 def __init__(self, klik_key, klik_secret, **kwargs):10 self.APIUrl = 'https://klikodoo.id/api/wa/'11 self.klik_key = klik_key or ''12 self.klik_secret = klik_secret or ''13 14 def auth(self):15 #if not self.klik_key and not self.klik_secret:16 # raise UserError(_('Warning! Please add Key and Secret Whatsapp API on General Settings'))17 try:18 requests.get(self.APIUrl+'status/'+self.klik_key+'/'+self.klik_secret, headers={'Content-Type': 'application/json'})19 except (requests.exceptions.HTTPError,20 requests.exceptions.RequestException,21 requests.exceptions.ConnectionError) as err:22 raise Warning(_('Error! Could not connect to Whatsapp account. %s')% (err))23 24 def logout(self):25 url = self.APIUrl + 'logout'26 data = {}27 data['instance'] = self.klik_key28 data['key'] = self.klik_secret29 get_version = request.env["ir.module.module"].sudo().search([('name','=','base')], limit=1)30 data['get_version'] = get_version and get_version.latest_version31 data_s = {32 'params' : data33 }34 req = requests.post(url, json=data_s, headers={'Content-Type': 'application/json'})35 res = json.loads(req.text)36 return res['result']37 38 39 def get_count(self):40 data = {}41 url = self.APIUrl + 'count/' + self.klik_key +'/' + self.klik_secret42 data_req = requests.get(url, data=json.dumps(data), headers={'Content-Type': 'application/json'})43 res = json.loads(data_req.text)44 #print ('===res===',res)45 return res.get('result') and res['result'] or {}46 47 def get_request(self, method, data):48 url = self.APIUrl + 'get/' + self.klik_key +'/' + self.klik_secret + '/' + method49 data_req = requests.get(url, data=json.dumps(data), headers={'Content-Type': 'application/json'})50 res = json.loads(data_req.text)51 return res.get('result') and res['result'] or {}52 53 def post_request(self, method, data):54 url = self.APIUrl + 'post/'55 data= json.loads(data)56 data['instance'] = self.klik_key57 data['key'] = self.klik_secret58 data['method'] = method59 get_version = request.env["ir.module.module"].sudo().search([('name','=','base')], limit=1)60 data['get_version'] = get_version and get_version.latest_version61 data_s = {62 'params' : data63 }64 response = requests.post(url, json=data_s, headers={'Content-Type': 'application/json'})65 if response.status_code == 200:66 message1 = json.loads(response.text)67 message = message1.get('result').get('message')68 chatID = message.get('id') and message.get('id').split('_')[1]69 return {'chatID': chatID, 'message': message}70 else:71 return {'message': {'sent': False, 'message': 'Error'}}72 73 def get_phone(self, method, phone):74 url = self.APIUrl + 'post/' + self.klik_key + '/'+self.klik_secret +'/'+ method + '/' + phone75 data = requests.get(url, headers={'Content-Type': 'application/json'})76 res = json.loads(data.text)...

Full Screen

Full Screen

TestHelpIChoiceMetode.py

Source:TestHelpIChoiceMetode.py Github

copy

Full Screen

1import sys2import os3from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage45# Connection6device = MonkeyRunner.waitForConnection()7#device.wake() #pobudjuje uredjaj i sam od sebe upali i rotaciju telefona8MonkeyRunner.sleep(8)910print('\nTest - Testiranje Type Metode')1112# Setuje/podesava path varijablu sa punim imenom .apk fajla13package = 'io.selendroid.testapp'14activity = '.HomeScreenActivity'15runComponent = package + '/' + activity16# Pokrece (Run) komponentu17device.startActivity(component=runComponent)1819#ispisuje poruku o pokrenutoj aplikaciji20#MonkeyRunner.help('io.selendroid.testapp') #Ne znam sta je uradila ova komanda???2122#komanda za izbor nke od zeljenih opcija napisanih u vidu liste23y = MonkeyRunner.choice("Izaberite koliko ponavljanja zelite", [1, 2, 3, 4, 5])2425# Pauzira izvrsenje programa na 3 sekunde da bi se aktivnost ucitala26MonkeyRunner.sleep(5)2728x = 1 29while (x <= y):30 print "Krug: ", x31 x = x + 132 #klik na EN Button33 device.touch(362, 136, "DOWN_AND_UP")34 #klik na No, no35 device.touch(352, 450, "DOWN_AND_UP")36 #klik na folder37 device.touch(370, 220, "DOWN_AND_UP")38 #klik na polje za Username39 device.touch(230, 172, "DOWN_AND_UP")40 MonkeyRunner.sleep(3)41 #ovde stavi type() metodu42 device.type("bane")43 MonkeyRunner.sleep(3)44 #klik na E-mail polje45 device.touch(104, 302, "DOWN_AND_UP")46 #ovde stavi drugu type() metodu47 device.type("bane1manojlovic@gmail.com")48 #klik na Password polje49 device.touch(70, 448, "DOWN_AND_UP")50 #ovde stavi narednu type() metodu51 device.type("MojaLozinka")52 #povukao sam ekran na gore53 device.drag((232, 400), (242, 110), 1.0, 10)54 MonkeyRunner.sleep(3)55 #klik nA IZBOR JEZIKA56 device.touch(436, 428, "DOWN_AND_UP")57 MonkeyRunner.sleep(3)58 #stikliram Python59 device.touch(420, 482, "DOWN_AND_UP")60 MonkeyRunner.sleep(3)61 #povlacim ekran na gore62 device.drag((250, 370), (250, 90), 1.0, 10)63 MonkeyRunner.sleep(3)64 #stikliram "I accept adds"65 device.touch(24, 388, "DOWN_AND_UP")66 MonkeyRunner.sleep(3)67 #klik na Register User dugme (prvo)68 device.touch(220, 466, "DOWN_AND_UP")69 MonkeyRunner.sleep(5)70 #klik na Register User dugme (drugo)71 device.touch(230, 360, "DOWN_AND_UP")72 MonkeyRunner.sleep(5)73 ...

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 SeleniumBase 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