Unable to perform action chains with Appium Python Client - selenium-webdriver

I have spent much time to find a way to perform right click with appium python client on a application in windows platform. Unfortunately, I get the following exception:
selenium.common.exceptions.WebDriverException: Message: Currently only pen and touch pointer input source types are supported
My code is in the following lines:
import unittest
from typing import List, Optional, Tuple, TypeVar
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
class SimpleCalculatorTests(unittest.TestCase):
#classmethod
def setUpClass(self):
# set up appium
desired_caps = {}
desired_caps["app"] = "Root"
desired_caps["deviceName"] = "WindowsPC"
desired_caps["platformName"] = "Windows"
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities=desired_caps)
#classmethod
def tearDownClass(self):
self.driver.quit()
def test_initialize(self):
communation_object = self.driver.find_element(By.XPATH, "/Pane[#ClassName=\"#32769\"][#Name=\"Desktop 1\"]/Window[#Name=\"ETS5™ - Neues Projekt\"][#AutomationId=\"windowApplication\"]/Custom[#AutomationId=\"eTS4UC\"]/Custom[#ClassName=\"Workspace\"]/Custom[#ClassName=\"ContentPanelContainer\"]/Custom[#AutomationId=\"Control\"]/Custom[#ClassName=\"ActiveComObjectDetailView\"]/DataGrid[#ClassName=\"DataGrid\"]/DataItem[#ClassName=\"DataGridRow\"][#Name=\"21: Ventilausgang 1 (Bezeichnung) - Eingang - Stellgröße\"]/Custom[#ClassName=\"DataGridCell\"][#Name=\"Ventilausgang 1 (Bezeichnung) - Eingang\"]/Text[#ClassName=\"TextBlock\"][#Name=\"Ventilausgang 1 (Bezeichnung) - Eingang\"]")
actions = ActionChains(self.driver)
actions.context_click(communation_object)
actions.perform()
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(SimpleCalculatorTests)
unittest.TextTestRunner(verbosity=2).run(suite)
Is there any alternative to perform right click?

Related

AttributeError: 'usando_unittest' object has no attribute 'driver' IN AN AUTOMATION PROCESS

I'm starting to automate some processes and have problems with my code. I saw a tutorial of selenium but when i want to run the code, Visual Studio Code give me this Error:
ERROR: test_buscar (__main__.usando_unittest)
AttributeError: 'usando_unittest' object has no attribute 'driver'
This is my code
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import time
class usando_unittest(unittest.TestCase):
def setup(self, driver):
self.driver = webdriver.Chrome(executable_path=r"C:PATH")
def test_buscar(self):
driver = self.driver
driver.get('http://www.google.com')
self.assertIn('Google', driver.title)
elemento = driver.find_element('id','input')
elemento.send_keys('Selenium')
elemento.send_keys(Keys.RETURN)
time.sleep(2)
assert'No se encontro el elemento' not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == '__main__':
unittest.main()
For privacy, I didn't put the PATH in the code.
I need Help Please.
Thanks

response status is not 200 on running webdriver to get url and on running beautiful soup to extract content, it throws attribute error

I have been trying to web scrape hotel reviews but on multiple page jumps, the url of the webpage doesn't change. So I am using webdriver from selenium to work this out. It is not showing any error but on checking if the response status is 200, it is showing false. In addition to that, running the line of code which I have mentioned below generates an error. If anyone can fix the issue, effort will be highly appreciated!
!pip install selenium
from selenium import webdriver
import requests
from bs4 import BeautifulSoup
import pandas as pd
# install chromium, its driver, and selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
code = wd.get('https://www.goibibo.com/hotels/highland-park-hotel-in-trivandrum-1383427384655815037/?hquery={%22ci%22:%2220211209%22,%22co%22:%2220211210%22,%22r%22:%221-2-0%22,%22ibp%22:%22v15%22}&hmd=766931490eb7863d2f38f56c6185a1308de782c89dfeeea59d262b827ca15441bf50472cbfdc1ee84aeed8af756809a2e89cfd6eaea0fa308c1ca839e8c313d016ac0f5948658353cf30f1cd83050fd8e6adb2e55f2a5470cadeb0c28b7becc92ac44d81966b82408effde826d40fbff47525e09b5f145e321fe6d104e12933c066323798e33a911e0cbed7312fc1634f8f92fe502c8602556c9a02f34c047d04ff1400c995799156776c1a04e218d6486493edad5b0f7e51a5ea25f5f1cb4f5ed497ee9368137f6ec73b3b1166ee7c1a885920b90c98542e0270b4fa9004005cfe87a4d1efeaedc8e33a848f73345f09bec19153e8bf625cc7f9216e692a1bcc313e7f13a7fc091328b1fb43598bd236994fdc988ab35e70cf3a5d1856c0b0fa9794b23a1a958a5937ac6d258d121a75b7ce9fc70b9a820af43a8e9a3f279be65b5c6fbfff2ba20bfb0f3e3ee425f0b930bf671c50878a540c6a9003b197622b6ab22ae39e07b5174cb12bebbcd2a132bb8570e01b9e253c1bd83cb292de97a&cc=IN&reviewType=gi&vcid=3877384277955108166&srpFilters={%22type%22:[%22Hotel%22]}')
str(code) == "<Response [200]>"
**Output: ** False
soup = BeautifulSoup(code.content,'html.parser')
On running the below line of code, there comes an error:
AttributeError Traceback (most recent call
last) in () ----> 1 soup
= BeautifulSoup(code.content,'html.parser')
AttributeError: 'NoneType' object has no attribute 'content'
get()
get(url: str) loads a web page in the current browser session and doesn't returns anything.
Hence, as per your code, code will be always NULL.
Solution
To validate the Response you can adopt any of the two approaches:
Using requests.head():
import requests
request_response = requests.head(https://www.goibibo.com/hotels/highland-park-hotel-in-trivandrum-1383427384655815037/?hquery={%22ci%22:%2220211209%22,%22co%22:%2220211210%22,%22r%22:%221-2-0%22,%22ibp%22:%22v15%22}&hmd=766931490eb7863d2f38f56c6185a1308de782c89dfeeea59d262b827ca15441bf50472cbfdc1ee84aeed8af756809a2e89cfd6eaea0fa308c1ca839e8c313d016ac0f5948658353cf30f1cd83050fd8e6adb2e55f2a5470cadeb0c28b7becc92ac44d81966b82408effde826d40fbff47525e09b5f145e321fe6d104e12933c066323798e33a911e0cbed7312fc1634f8f92fe502c8602556c9a02f34c047d04ff1400c995799156776c1a04e218d6486493edad5b0f7e51a5ea25f5f1cb4f5ed497ee9368137f6ec73b3b1166ee7c1a885920b90c98542e0270b4fa9004005cfe87a4d1efeaedc8e33a848f73345f09bec19153e8bf625cc7f9216e692a1bcc313e7f13a7fc091328b1fb43598bd236994fdc988ab35e70cf3a5d1856c0b0fa9794b23a1a958a5937ac6d258d121a75b7ce9fc70b9a820af43a8e9a3f279be65b5c6fbfff2ba20bfb0f3e3ee425f0b930bf671c50878a540c6a9003b197622b6ab22ae39e07b5174cb12bebbcd2a132bb8570e01b9e253c1bd83cb292de97a&cc=IN&reviewType=gi&vcid=3877384277955108166&srpFilters={%22type%22:[%22Hotel%22]})
status_code = request_response.status_code
if status_code == 200:
print("URL is valid/up")
else:
print("URL is invalid/down")
Using urlopen():
import requests
import urllib
status_code = urllib.request.urlopen(https://www.goibibo.com/hotels/highland-park-hotel-in-trivandrum-1383427384655815037/?hquery={%22ci%22:%2220211209%22,%22co%22:%2220211210%22,%22r%22:%221-2-0%22,%22ibp%22:%22v15%22}&hmd=766931490eb7863d2f38f56c6185a1308de782c89dfeeea59d262b827ca15441bf50472cbfdc1ee84aeed8af756809a2e89cfd6eaea0fa308c1ca839e8c313d016ac0f5948658353cf30f1cd83050fd8e6adb2e55f2a5470cadeb0c28b7becc92ac44d81966b82408effde826d40fbff47525e09b5f145e321fe6d104e12933c066323798e33a911e0cbed7312fc1634f8f92fe502c8602556c9a02f34c047d04ff1400c995799156776c1a04e218d6486493edad5b0f7e51a5ea25f5f1cb4f5ed497ee9368137f6ec73b3b1166ee7c1a885920b90c98542e0270b4fa9004005cfe87a4d1efeaedc8e33a848f73345f09bec19153e8bf625cc7f9216e692a1bcc313e7f13a7fc091328b1fb43598bd236994fdc988ab35e70cf3a5d1856c0b0fa9794b23a1a958a5937ac6d258d121a75b7ce9fc70b9a820af43a8e9a3f279be65b5c6fbfff2ba20bfb0f3e3ee425f0b930bf671c50878a540c6a9003b197622b6ab22ae39e07b5174cb12bebbcd2a132bb8570e01b9e253c1bd83cb292de97a&cc=IN&reviewType=gi&vcid=3877384277955108166&srpFilters={%22type%22:[%22Hotel%22]}).getcode()
if status_code == 200:
print("URL is valid/up")
else:
print("URL is invalid/down")

Use Selenium chrome and gecko driver as the same time

Is there a way to fire off the use of the chrome and gecko webdriver at the same time without duplicating code?
Right now I'm swapping between the two.
from selenium import webdriver
from selenium.common.exceptions import
def setUp(self):
# self.browser = webdriver.Firefox()
self.browser = webdriver.Chrome()
Yes, you can do it. However there must be some place where you specify the browser to be opened.
Browser name to be opened can be passed as an argument to setup method
from selenium import webdriver
def setUp(self, browserName):
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
Browser name to be opened can be read from some configuration/properties file.
from selenium import webdriver
def setUp(self):
browserName = #Code to read value from configuration file
if browserName == "Firefox":
self.browser = webdriver.Firefox()
elif browserName == "Chrome" :
self.browser = webdriver.Chrome()
You haven't specified the environment, so I'll go with this. This is how it could be done in Katalon Studio:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver driver1 = new ChromeDriver()
WebDriver driver2 = new FirefoxDriver()
DriverFactory.changeWebDriver(driver1)
// test with Chrome
DriverFactory.changeWebDriver(driver2)
// test with Firefox

Appengine serve gzipped files

I'm using AppEngine to store some pickled python objects in my app. I want to serve these to the user directly, and I'm simply using the X-AppEngine-Blobkey header to serve the files to the user with a file.pickle.gz filename. However, when I try to extract these on my computer (Mac OS) using a simple double click, the files are turned into file.pickle.gz.cpgz.
I thought it was my browser being sneaky and extracting them, but I don't think so, since
pickle.load('file.pickle.gz')
Doesn't work, and neither does
pickle.load('file.pickle.gz.cpgz')
To store the files, I use:
blobfile = files.blobstore.create(mime_type='application/gzip')
with files.open(blobfile, 'a') as f:
gz = gzip.GzipFile(fileobj=f,mode='wb')
gz.write(my_pickled_object)
gz.close()
files.finalize(blobfile)
I think I'm not understanding the way gzips work. Can someone explain?
Are you sure file.pickle.gz.cpgz is the result of your double-clicking on the file.pickle.gz file you downloaded? Usually ".cpgz" is a different kind of archive file.
I can get the code you posted to work in a development server without significant changes. Here's the code, if it helps:
#!/usr/bin/env python
from __future__ import with_statement
import gzip
import pickle
from google.appengine.api import files
from google.appengine.api import memcache
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp import util
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write('Hello world! make get')
class MakeFileHandler(webapp.RequestHandler):
def get(self):
data = pickle.dumps({'a':1, 'b':True, 'c':None})
blobfile = files.blobstore.create(mime_type='application/gzip')
with files.open(blobfile, 'a') as f:
gz = gzip.GzipFile(fileobj=f,mode='wb')
gz.write(data)
gz.close()
files.finalize(blobfile)
memcache.set('filekey', files.blobstore.get_blob_key(blobfile))
self.redirect('/')
class GetFileHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
blobkey = memcache.get('filekey')
if blobkey:
self.send_blob(blobkey)
else:
self.response.out.write('No data key set back')
def main():
application = webapp.WSGIApplication([('/', MainHandler),
('/make', MakeFileHandler),
('/get', GetFileHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Click on "make", then click on "get". A file named "get.gz" is downloaded to your ~/Downloads/ folder (at least in Chrome). Double-click on it to produce a file named "get". Then:
% python
>>> import pickle
>>> pickle.load(open('get'))
{'a': 1, 'c': None, 'b': True}

Web2py Google App Engine Testing

I'm building an GAE app with web2py and am struggling with setting up a test framework.
I've looked into:
web2py_utils
nosegae
Googler Ikai Lan's suggestions
gaetestbed which was merged into GAE apis
Here's a unit test I attempted:
import unittest
import nose
from nose.tools import *
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_itil
class UserModelTest(unittest.TestCase):
def setUp(self):
# First, create an instance of the Testbed class.
self.testbed = testbed.Testbed()
# Then activate the testbed, which prepares the service stubs for use.
self.testbed.activate()
# Initialize the datastore stub with this policy.
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
self.env = new_env(app='fb', controller='default')
self.db = copy_db(self.env, db_name='db', db_link='sqlite:memory')
self.user = self.db.auth_user.insert(first_name='Bob', last_name='Narley', fb_id=1, password='testtest')
self.dream = self.db.dream.insert(title='Graduate UC Santa Cruz with Computer Science degree by June 8, 2012.',
type='education', owner = self.user, progress=92.0)
self.task1 = self.db.task.insert(dream=self.dream, title='Buy batteries for calculator', solution='Go to Walmart at 12:00pm October 30, 2012 and buy Duracell AAA.',
status=1)
self.task2 = self.db.task.insert(dream=self.dream, title='Make Winston happy',
solution='Make banana milk',
status=0)
self.user.update_record(tasks=[self.task1, self.task2])
def tearDown(self):
self.testbed.deactivate()
def test_create_user(self):
assert_equal('Bob', self.user.first_name)
assert_equal(1, self.user.fb_id)
assert_equal('testtest', self.user.password)
def test_user_has_many_tasks(self):
tasks = self.db(self.db.task.id.belongs(self.user.tasks)).select()
assert_equal(2, len(tasks))
run_fb_tests.py:
from web2py_utils.test_runner import run
import sys
run(path = sys.path[0],
app = 'fb',
test_key = 'superSecret',
test_options = {'verbosity': 3, 'with-gae': True, 'without-sandbox': True},
coverage_report = 'logs/coverage_report.txt',
DO_COVER = True,
DO_NOSE = True,)
I get the following error when execute my run_fb_tests.py
ImportError: No module named google.appengine.ext
I've been banging my head for days now with many errors. This is only one of many
How do you setup a testing framework in web2py for GAE apps?
Where is your script run_fb_tests.py? If it is in the web2py folder I get a similar error, but if you place it in google_appenine, or in the containing folder of the google_appengine then I get no import errors.

Resources