如何使用Google App Engine运行Selenium测试? [英] How do I run Selenium tests with Google App Engine?

查看:159
本文介绍了如何使用Google App Engine运行Selenium测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们希望使用Google App Engine每4小时运行一次cron Selenium测试(稍后我们可能会更改此小时数)。我们希望收到一封包含测试结果的电子邮件。我想知道我如何创建第一个测试。我想通过Google Chrome扩展程序测试 https://inbox.google.com/ - 进入我们的网站,登录,点击保存更改,安装扩展程序,然后输入 https://inbox.google.com/,登录并检查扩展是否工作。问题是我不知道如何设置测试,我必须使用URL设置它们,我该如何做?我必须为每个测试提供一个不同的URL,还是可以使用一个URL运行所有测试?以下是我从 http://app.crossbrowsertesting.com/selenium/run 收到的代码:

 #请访问http://selenium-python.readthedocs.org/en/latest/index.html了解详细安装和指令

导入unittest
来自selenium import webdriver

class SeleniumCBT(unittest.TestCase):
def setUp(self):
caps = {}
$ b $ 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'

#启动服务器上的远程浏览器
self.driver = webdriver.R emote(
desired_capabilities = caps,
command_executor =http:// [username]:[password] @ hub.crossbrowsertesting.com:80 / wd / hub


self.driver.implicitly_wait(20)

def test_CBT(self):

#载入页面url
print('加载Url')
self.driver.get('http://crossbrowsertesting.github.io/selenium_example_page.html')

#最大化窗口
print('最大化窗口')
self.driver.maximize_window()

#检查标题
print('Checking title')
self.assertTrue(Selenium Test Example Pagein self。 driver.title)
$ b $ def tearDown(self):
print(Done with session%s%self.driver.session_id)
self.driver.quit()

if __name__ =='__main__':
unittest.main()

我也下载了Selenium(2.44.0)并将其放入 libs 目录,如果我包含以下几行:

  import sys 
sys.path.insert(0,'libs')

我可以导入硒吗? (来自selenium import webdriver 的)还是我还要做别的事情?



我们使用Python 2.7我们可以升级到Python 3)。

解决方案

Selenium可让您控制(AKA 自动化)浏览器 - 并且在App Engine实例上,您没有浏览器,您也不能安装它。 App Engine是一个平台(PaaS - 平台即服务),供您编写Web应用程序(服务器端), 运行web 客户端,例如浏览器。



相反,您应该将基础设施 IaaS)产品:例如,在那个字段中,Google使用Google Compute Engine和使用容器(docker)在其上创建的图层。



补充:除了几个 .so s之外,显然只需要驱动firefox,selenium webdriver python语言绑定似乎确实是纯Python - if使用Selenium严格限制为 webdriver.Remote 来驱动远程Selenium服务器,如app.crossbrowsertesting.com/selenium/run,如注释中的OP所示,很可能将这些内容解包到应用程序主目录的子目录中可以让您在GAE上执行此操作。



我是sa y可能,而不是确定,因为我无法确认selenium远程协议是否以与App Engine提供的套接字功能子集兼容的方式在这些源中实现。



通过代码检查确定是否是这种情况将花费比一个简单的试验和错误方法更长的时间 - 因此,由于试用部分不会破坏任何东西(即使在最坏的情况下(我们都知道!)。

至于其他的问题,如果硒确实有效,那么投入一个如果OP总是希望一起运行所有测试(从来不只是其中的一部分测试),那么应用程序的单个URL加载并运行所有测试的处理程序将是完全可行的 - 该部分根本不难。可能会破坏的部分(可能会以不可修复的方式破坏,取决于Selenium远程协议的编码细节)是上一部分 - 这归结为能够使用Selenium的远程程序执行hello world的webdriver。为了确定,正如我所说的,反复试验是最可行的方法。

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 .sos 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.

这篇关于如何使用Google App Engine运行Selenium测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆