- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Python 和 selenium 的新手。我需要编写一个可以在我的测试用例中重用的登录模块。这是我的 2 个文件。我需要帮助来调用登录模块,以便浏览器启动并且用户可以登录。然后第二个模块启动,测试用例开始(在同一个浏览器中)。我在 2 个单独的文件中编写了 2 个类。我的代码如下:
我的登录.py文件
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
import unittest
class myLoginclass(unittest.TestCase):
@classmethod
def test_TC_1_login_page(self):
self.driver = webdriver.Firefox()
self.driver.get(http://www.gmail.com)
self.driver.find_element_by_xpath(".//*[@id='name-group']/input").send_keys("HELLO")
self.driver.find_element_by_xpath(".//*[@id='password-group']/input").send_keys("WORLD")
self.driver.find_element_by_id("loginButton").click()
if __name__ == '__main__':
unittest.main(failfast=True, exit=False)
myorder.py 文件:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
import unittest
from mylogin import myLoginclass
class myorderclass(unittest.TestCase):
@classmethod
def test_TC_2_orderProcess(self):
self.driver.find_element_by_xpath("".//*[@id='aoTkt']/div/div")).click()
self.driver.find_element_by_xpath(".//*[@id='presales']/input").click()
self.driver.find_element_by_link_text("DISPATCH").click()
self.driver.find_element_by_id("submitButton").click()
if __name__ == '__main__':
unittest.main(failfast=True, exit=False)
最佳答案
使用类继承。根据您的用例,使用 setUp() 或 setUpClass() 调用登录函数。
from mylogin import myLoginclass
class myorderclass(myLoginclass):
def setUp(self):
self.test_TC_1_login_page()
关于 python Selenium : How to reuse a class from another class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49288730/
我在 WebApi 项目中使用 DryIoc。默认重用设置为 Reuse.InWebRequest。在某些情况下,我需要在请求期间解析新实例。使用 Reuse.InCurrentScope 时,我可以
问题:当 Collection View 单元格滚动到屏幕外并重新使用时,对 Collection View 单元格的引用会发生什么情况?我在不使用“出队”的情况下提供细胞的所有尝试都失败了。有没有办
有什么想法可以解决如下所示的问题吗?根据我在网上找到的信息,它与重用 tensorflow 范围的问题有关,但没有任何效果。 ValueError: Variable rnn/basic_rnn_ce
去年,我参加了C++的数据结构类(class),因此以模板代码实现了所有主要的数据结构。我将所有内容都保存在闪存驱动器中,因为我觉得在生活中的某个时刻,我会再次使用它。我想我最终编程的东西将需要B树,
几年前,有人告诉我一项关于代码重用的研究。显然,发现程序员在搜索要重用的代码时平均有 7 分钟的时间。如果他们在那个窗口中没有找到适合他们需要的代码,他们就会编写自己的代码。 这是在需要仔细管理代码以
我一直是一个糟糕的程序员,因为我正在做复制和粘贴。一个例子是,每次我连接到数据库并检索记录集时,我都会复制以前的代码并编辑,复制设置 datagridview 的代码并进行编辑。我知道短语代码重用,但
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
关闭。这个问题需要多问focused 。目前不接受答案。 已关闭 3 年前。 已锁定。这个问题及其答案是locked因为这个问题是题外话,但却具有历史意义。目前不接受新的答案或互动。 任何代码都可以以
我通常会维护代码片段,我可以在 Wikidpad 个人 wiki 中重新使用这些代码片段,并带有一个小索引页面,可以将我带到我想要的任何代码。 我想与我的团队分享这些片段,并正在寻找简单的方法来做到这
我有以下路线,id 是一个可选参数,因此用户可以加载信息,或者如果没有提供 id,他们可以添加信息。我希望能够重用组件,这样页面就不必重新加载(在 ngOnInit 中调用 api),但是因为它们是两
我想对多个数据表应用相同的聚合,而不需要重写聚合方案。 考虑 dt1 <- data.table(id = c(1,2), a = rnorm(10), b = rnorm(10), c = rnor
我的公司有两到三个使用大量通用代码的 Web 应用程序——自定义 MVC 框架、实用程序类、JavaScript 库等等。 我们不想在每个应用程序中复制所有这些代码,因为我们最终会使用它的几个略有不同
许多个月前,我开始将我的音乐存储为 MP3。我疯狂地下载,然后将它们全部转储到一个文件夹中。在收集了数千首歌曲后,我一团糟。在我的空闲时间整理了所有音乐两年后,我已经把它放到了我图书馆的“D”部分。我
我正在尝试学习specflow,现在。 目前我有 2 个功能文件。 在第二个功能文件中,我重用了第一个功能文件中的一个步骤。 Specflow 自动识别第一个功能文件中的步骤,当 Specflow 为
有时我会偶然发现我想表达“请使用最后一个参数两次”的问题,例如为了编写无点样式或避免使用 lambda。例如。 sqr x = x * x 可以写成 sqr = doubleArgs (*) wher
这个问题已经有答案了: Javascript: how to pass found string.replace value to function? (3 个回答) 已关闭 7 年前。 我有一个功能
我想查找字符串中出现的字符(如果它们出现在某个“标记”字符之前或之后)。 所以我的标记是-,字符串是“a b-c d”。我想按顺序查找 b 和 c。 我试过了 re.findall(r'(-[a-z]
这个问题在这里已经有了答案: How to set variable reuse back to False in Tensorflow? (2 个答案) 关闭 6 年前。 有没有办法取消设置变量范
我会尽量简明扼要.. 我目前正在开发一个小型的实时“MMO”,并希望减少主机 -> 客户端的带宽使用。 其中成本最高的是字符串的使用,在大多数情况下,字符串会不断重复并发送给客户端。由于它们的性质(无
我读到 ThreadPoolExecutor 有线程池,这个池注定要降低创建新线程的成本(至少我是这样理解下面的短语): When you send a task to the executor, i
我是一名优秀的程序员,十分优秀!