Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python Django在本地和远程服务器上运行Selenium测试?_Python_Django_Testing_Selenium - Fatal编程技术网

如何使用Python Django在本地和远程服务器上运行Selenium测试?

如何使用Python Django在本地和远程服务器上运行Selenium测试?,python,django,testing,selenium,Python,Django,Testing,Selenium,许多Selenium测试示例都是这样开始的: from selenium import webdriver driver = webdriver.Firefox() driver.self.driver.get("some hardcoded url") 有没有办法避免将URL硬编码到测试中,并以某种方式从启动测试的环境中检索域名?如果您真的想走环境路线,下面是如何做到的: import os print os.environ['HOME'] 另一种选择是为不同的服务器提供不同的配置文件,

许多Selenium测试示例都是这样开始的:

from selenium import webdriver

driver = webdriver.Firefox()
driver.self.driver.get("some hardcoded url")

有没有办法避免将URL硬编码到测试中,并以某种方式从启动测试的环境中检索域名?

如果您真的想走环境路线,下面是如何做到的:

import os
print os.environ['HOME']

另一种选择是为不同的服务器提供不同的配置文件,并在初始化测试线束时对其进行解析,尽管如果您有100个测试文件,则解析其中每一个的配置可能不太理想。

它会打印“home/sashko”。是的,这只是一个例子。(在bash上)导出FOO_URL=“”,然后您可以通过os.environ(“FOO_URL”)访问它对不起,但我真的不明白(在bash上)如何导出FOO_URL=“bringvictory.com”将影响远程启动的测试。还是应该在脚本文件中编写这样的命令?