We want to use Google App Engine to run Selenium tests with cron every 4 hours (later we may change this number of hours). We want to receive an email with the results of the tests. I want to know how I create the first test. I want to test https://inbox.google.com/ with our extension with Google Chrome - enter our website, login, click "Save changes", install the extension, then enter https://inbox.google.com/, login and check that the extension works. The problem is that I don't know how to setup the tests, do I have to setup them with a URL and how do I do it? Do I have to give each test a different URL or can I run all the tests with one URL? Here is the code I received from http://app.crossbrowsertesting.com/selenium/run:
# Please visit http://selenium-python.readthedocs.org/en/latest/index.html for detailed installation and instructions
import unittest
from selenium import webdriver
class SeleniumCBT(unittest.TestCase):
def setUp(self):
caps = {}
caps['name'] = 'Chrome Inbox Test'
caps['build'] = '1.0'
caps['browser_api_name'] = 'Chrome39x64'
caps['os_api_name'] = 'Win8.1'
caps['screen_resolution'] = '1280x1024'
caps['record_video'] = 'true'
caps['record_network'] = 'true'
caps['record_snapshot'] = 'true'
#start the remote browser on our server
self.driver = webdriver.Remote(
desired_capabilities=caps,
command_executor="http://[username]:[password]@hub.crossbrowsertesting.com:80/wd/hub"
)
self.driver.implicitly_wait(20)
def test_CBT(self):
#load the page url
print('Loading Url')
self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')
#maximize the window
print('Maximizing window')
self.driver.maximize_window()
#check the title
print('Checking title')
self.assertTrue("Selenium Test Example Page" in self.driver.title)
def tearDown(self):
print("Done with session %s" % self.driver.session_id)
self.driver.quit()
if __name__ == '__main__':
unittest.main()
I also downloaded Selenium (2.44.0) and put it in the libs
directory, if I include the following lines:
import sys
sys.path.insert(0, 'libs')
Can I import selenium? (from selenium import webdriver
) or do I have to do something else?
We are using Python 2.7 (although we can upgrade to Python 3).
Selenium lets you control (AKA automate) a browser -- and, on an App Engine instance, you don't have a browser, nor can you install one.
App Engine is a platform (PaaS -- "platform as a service") for you to write (the server side of) web applications, not to run web clients such as browsers.
Rather, you should look at infrastructure as a service (IaaS) offerings: for example, in that field, Google has "Google Compute Engine" and layers built on top of it using containers (docker).
Added: with the exception of a couple of .so
s apparently only needed to drive firefox, the selenium webdriver python language bindings do appear to be pure Python -- if the use of Selenium is strictly limited to webdriver.Remote
to drive a remote Selenium server such as app.crossbrowsertesting.com/selenium/run , as indicated by the OP in a comment, it's possible that unpacking the lot into a subdirectory of your app's main directory will let you do that on GAE.
I say "possible", not "certain", because I can't confirm that the selenium remote protocol is implemented in those sources in a way that's compatible with the subset of socket functionality offered by App Engine.
Determining whether that is the case by code inspection would take far longer than a simple trial and error approach -- therefore, since the "trial" part won't break anything (even in the worst case, it will just terminate with an exception), I would recommend exactly that (and let us all know!).
As for the other Qs, if selenium does work, devoting a single URL of the app to a handler which loads and runs all tests would be perfectly feasible, if the OP always wants to run all tests together (never just a subset of them) -- that part's not difficult at all. The part that might break (and might possibly break in an unfixable way, depending on the details of how the selenium remote protocol is coded) is the previous one -- which boils down to being able to do a "hello world" with selenium's remote webdriver. And to ascertain that, as I said, trial and error is the most viable approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With