Z
Z
Zelyoniy2018-06-19 14:04:57
Python
Zelyoniy, 2018-06-19 14:04:57

How to correctly change the autotest code to launch the browser?

Absolute newbie in python + selenium autotests. Got a question.
Pieces of code from an elementary test.
The browser opens, there are no errors in the pycharm console:

from selenium import webdriver

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://ya.ru')

The browser does not open, there are no errors in the pycharm console:
from selenium import webdriver

def auth(self):
    self.driver = webdriver.Chrome()
    self.driver.maximize_window()
    self.driver.get("http://ya.ru")

What is the correct way to put chrome opening in a function?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Yangunaev, 2018-06-19
@Avg00r

You're declaring a function, but you're doing it without respect and don't call it. Therefore, nothing happens - try writing its call.
In addition, you need to add a description of the class, you are passing the self parameter, which points to an instance of the class, but there is no class itself.

from selenium import webdriver
import unittest


class auth_test(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome()

    def test_auth(self):
        self.auth()

    def tearDown(self):
        self.driver.close()

    def auth(self):
        self.driver.get("http://ya.ru")


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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question