英文:
Facing this error in Pytest on selenium python
问题
import time
import self as self
from pytest import mark
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from setuptools import setup
@mark.execute
class First_Tests:
def test_first(self, setup):
driver = setup['driver']
browser = setup['browser']
driver.get("https://shuftipro.com/")
driver.maximize_window()
def header_test(self, setup):
driver = setup['driver']
# Click on solution in header
solution = driver.find_element(By.ID, "menu-item-72751")
solution.click()
if driver.current_url == "https://shuftipro.com/solutions/":
print("land on solution page.")
else:
print("land on wrong page.")
obj = First_Tests()
obj.test_first(setup)
obj.header_test(setup)
如果我从参数中删除了"self"并运行程序,它会显示错误,test_first() 接受1个位置参数,但提供了3个。
英文:
import time
import self as self
from pytest import mark
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from setuptools import setup
@mark.execute
class First_Tests:
def test_first(self, setup):
driver = setup['driver']
browser = setup['browser']
driver.get("https://shuftipro.com/")
driver.maximize_window()
def header_test(self, setup):
driver = setup['driver']
# Click on solution in header
solution = driver.find_element(By.ID, "menu-item-72751")
solution.click()
if driver.current_url == "https://shuftipro.com/solutions/":
print("land on solution page.")
else:
print("land on wrong page.")
obj = First_Tests()
obj.test_first(self, setup)
obj.header_test(self, setup)
If I remove the "self" from parameter and run the program it showing me error that, test_first() takes 1 positional arguments but 3 were given
答案1
得分: 1
以下是翻译好的部分:
"one of easier way would be to use webdriver from selenium"
"使用Selenium中的webdriver是更简单的方法之一"
"driver = webdriver.Chrome()"
"driver = webdriver.Chrome()"
"and remove"
"并移除"
"driver = setup['driver']"
"driver = setup['driver']"
"browser = setup['browser']"
"browser = setup['browser']"
"and then get rid of setup as parameter."
"然后不再需要将setup作为参数传递。"
"The final code will look something like this:"
"最终的代码将类似于这样:"
"from pytest import mark"
"from pytest import mark"
"from selenium import webdriver"
"from selenium import webdriver"
"from selenium.webdriver.common.by import By"
"from selenium.webdriver.common.by import By"
"driver = webdriver.Chrome()"
"driver = webdriver.Chrome()"
"@mark.execute"
"@mark.execute"
"class First_Tests:"
"class First_Tests:"
"def test_first():"
"def test_first():"
"driver.get('https://shuftipro.com/')"
"driver.get('https://shuftipro.com/')"
"driver.maximize_window()"
"driver.maximize_window()"
"def header_test():"
"def header_test():"
"solution = driver.find_element(By.ID, 'menu-item-72751')"
"solution = driver.find_element(By.ID, 'menu-item-72751')"
"solution.click()"
"solution.click()"
"if driver.current_url == 'https://shuftipro.com/solutions/':"
"if driver.current_url == 'https://shuftipro.com/solutions/':"
"print('land on solution page.')"
"print('进入到解决方案页面。')"
"print('land on wrong page.')"
"print('进入到错误的页面。')"
"obj = First_Tests()"
"obj = First_Tests()"
"obj.test_first()"
"obj.test_first()"
"obj.header_test()"
"obj.header_test()"
英文:
one of easier way would be to use webdriver from selenium
driver = webdriver.Chrome()
and remove
driver = setup['driver']
browser = setup['browser']
and then get rid of setup as parameter.
The final code will look something like this:
from pytest import mark
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
@mark.execute
class First_Tests:
def test_first(self):
driver.get("https://shuftipro.com/")
driver.maximize_window()
def header_test(self):
# Click on solution in header
solution = driver.find_element(By.ID, "menu-item-72751")
solution.click()
if driver.current_url == "https://shuftipro.com/solutions/":
print("land on solution page.")
else:
print("land on wrong page.")
obj = First_Tests()
obj.test_first()
obj.header_test()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论