Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 获取多个url?这在硒中可能吗_Python_Unit Testing_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

Python 获取多个url?这在硒中可能吗

Python 获取多个url?这在硒中可能吗,python,unit-testing,selenium,selenium-webdriver,webdriver,Python,Unit Testing,Selenium,Selenium Webdriver,Webdriver,我有一个URL列表,我想为其编写一个小的冒烟测试 只需加载URL并断言标题,以确保它们是活动的。这可能吗?类标识YUnitTest.TestCase: def setUp(self): self.driver = webdriver.Chrome() driver = self.driver self.driver.implicitly_wait(30) @data('https://idsvr-test.sc.com/account/signin','https://launchpad-t

我有一个URL列表,我想为其编写一个小的冒烟测试

只需加载URL并断言标题,以确保它们是活动的。这可能吗?类标识YUnitTest.TestCase:

def setUp(self):

self.driver = webdriver.Chrome()
driver = self.driver
self.driver.implicitly_wait(30)

@data('https://idsvr-test.sc.com/account/signin','https://launchpad-test.sc.com/#&ui-      state=dialog','https://ambassador-test.sc.com/')  
def test_login_identity(self,url):  

self.driver.get("https://idsvr-test.sc.com/account/signin")
self.assertIn("Username / Password Sign In", self.driver.title)
elemU = self.driver.find_element_by_name("UserName").send_keys(User)
elemP = self.driver.find_element_by_name("Password").send_keys(sDecryptPassword)
self.driver.find_element_by_id("login").click()
try:

  self.assertEqual("MyTitle", self.driver.title)
  print("I asserted the Title")

except Exception as e:
  print(e)

try:
  self.driver.get("https://launchpad-test.sc.com/#&ui-state=dialog") 
  self.assertIn("Launch Pad",self.driver.title)
  ltitle = self.driver.title
  print( "New page" + ltitle)


except Exception as e:
 print(e)


 try:

  self.driver.get("https://ambassador-test.sc.com/")  
  self.assertIn("SC: Ambassador",self.driver.title)
  atitle = self.driver.title
  print(atitle)
 except Exception as e:
  print(e)
如果name==main:
unittest.main

这看起来确实像一个数据驱动的测试。在这种情况下,软件包有助于简化:

DDT数据驱动测试允许您将一个测试用例乘以 使用不同的测试数据运行它,并使其显示为多个 测试用例


应用@ddt和@data decorators基本上会为@data中传递的每个url自动生成一个测试方法。在本例中,unittest runner将执行3种测试方法。

非常感谢您。。。现在它正在运行,但它只运行前2个测试3次。。。第三个get.url无效。有什么想法吗?谢谢你help@user2744620不客气,前两步,你能详细描述一下正在发生的事情和你想发生的事情吗?谢谢。这就是正在发生的事情1。它获取第一个URL,登录发生,并声明标题。2.它获取第二个Url并断言倾斜。3.这2次重复大约3次,我有3次不同的开放会话。我想要的是,1。使用第一个Url登录。2.访问第二个url并断言第3页。访问/获取第三个Url并断言页面。等等我有大约5个网址,我想验证这一点。第一次登录时应记住已打开的会话,并允许剩余的URL在不使用任何uname/密码的情况下登录。@user2744620明白了,ddt仍然是您可以使用的smth。你能发布完整的代码吗?请编辑问题并将其发布在那里?只需编辑我的初始帖子并将代码发布在那里。谢谢你的时间。谢谢
from ddt import ddt, data

@ddt
class identity(unittest.TestCase):
    ...

    @data('url1', 'url2', 'url3')
    def test_login_identity(self, url):
        self.driver.get(url)
        # ...