- Checkout branch
03_remove_duplication
. - Open
CheckoutFeatureTest
insrc > test > java > exercises
. There is duplicate code that exists inLoginFeatureTest
, specifically thesetup()
andteardown()
methods. - Create a
BaseTest
class that executes these prerequisite and postrequisite test actions. - Migrate the
setup()
andteardown()
methods fromLoginFeatureTest
andCheckoutFeatureTest
and place them intoBaseTest
- Back in
LoginFeatureTest
andCheckoutFeatureTest
, extendBaseTest
like so:public class LoginFeatureTest extends BaseTest { ... }
- Also in
LoginFeatureTest
andCheckoutFeatureTest
remove the following line:as it's now redundant.protected WebDriver driver
- Delete
FullJourneyTest
and test the changes:mvn test
- If both tests run fine, use
git commit
orgit stash
, then checkout the next branch to proceed to the next exercise:
Next we will update our capabilities
in BaseTest
to test using the latest version of Google Chrome, which means we have to modify our code a bit to comply with the new W3C
protocol.
- Add a second
MutableCapabilities
object in thesetup()
method with the following details:MutableCapabilities sauceOpts = new MutableCapabilities(); sauceOpts.setCapability("username", sauceUsername); sauceOpts.setCapability("accessKey", sauceAccessKey); sauceOpts.setCapability("name", method.getName()); sauceOpts.setCapability("seleniumVersion", "3.141.59"); sauceOpts.setCapability("build", "saucecon19-best-practices"); sauceOpts.setCapability("tags", "['best-practices', 'saucecon19']");
- Next, modify the existing
MutableCapabilities
object called `capabilities with the following:MutableCapabilities capabilities = new MutableCapabilities(); capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOpts); capabilities.setCapability("sauce:options", sauceOpts); capabilities.setCapability("browserName", "googlechrome"); capabilities.setCapability("browserVersion", "71.0"); capabilities.setCapability("platformName", "windows 10");
- Run a test to ensure the build passes
mvn test
- Use
git stash
orgit commit
to discard or save your changes. Checkout the next branch to proceed to the next exercisegit checkout 04_configure_atomic_tests