课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using Page Objects in tests

Using Page Objects in tests

- [Instructor] Every web test needs to open and close the browser and use Selenium web driver to interact with the page. Rather than duplicating this code in every test method, you can extract it out and place it into methods that run before and after your test suite. For that, we'll use a base test class that every other test class can inherit from. This class lives under the source test Java directory. Let's start by declaring a web driver instance that can be used across all tests, and we'll make this protected so that it's accessible in all test classes that inherit from this one. So we can say protected static WebDriver driver. Next, we'll create a setup method and we can say public static void, and we'll call this setup. In this method, we can set up our chrome driver executable. So let's say chromedriver.setup. And we can also specify any preferred options. So let's say chrome options, we'll call this options, equals new chrome options. To run selenium tests in GitHub code…

内容