Partially externalize WebDriver tests

This change does a few things:

  1. Partially externalized WebDriver tests by using ChromeDriver
     as an implementation of WebDriver API in the external build.
  2. Refactored WebDriverRule.java to decouple the creation and
     using of WebDriver related stuff so we can have different
     implementations in internal and external builds.
  3. Refactored the usage of some internal libraries to have a
     central place to store all of them to make it easier to
     remove them in the external build.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=233661757
This commit is contained in:
shicong 2019-02-12 12:58:11 -08:00 committed by jianglai
parent 4097dae3b2
commit 76028ba1b4
75 changed files with 1743 additions and 28 deletions

View file

@ -0,0 +1,83 @@
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.webdriver;
import static google.registry.server.Fixture.BASIC;
import static google.registry.server.Route.route;
import com.googlecode.objectify.ObjectifyFilter;
import google.registry.model.ofy.OfyFilter;
import google.registry.module.frontend.FrontendServlet;
import google.registry.server.RegistryTestServer;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
/** Registrar Console Screenshot Differ tests. */
@RunWith(JUnit4.class)
public class OteSetupConsoleScreenshotTest {
@Rule
public final TestServerRule server =
new TestServerRule.Builder()
.setRunfiles(RegistryTestServer.RUNFILES)
.setRoutes(route("/registrar-ote-setup", FrontendServlet.class))
.setFilters(ObjectifyFilter.class, OfyFilter.class)
.setFixtures(BASIC)
.setEmail("Marla.Singer@google.com")
.build();
@Rule public final WebDriverRule driver = new WebDriverRule();
@Test
public void get_owner_fails() throws Throwable {
driver.manage().window().setSize(new Dimension(1200, 2000));
driver.get(server.getUrl("/registrar-ote-setup"));
driver.waitForElement(By.tagName("h1"));
driver.diffPage("unauthorized");
}
@Test
public void get_admin_succeeds() throws Throwable {
server.setIsAdmin(true);
driver.manage().window().setSize(new Dimension(1200, 2000));
driver.get(server.getUrl("/registrar-ote-setup"));
driver.waitForElement(By.tagName("h1"));
driver.diffPage("formEmpty");
driver.findElement(By.id("clientId")).sendKeys("acmereg");
driver.findElement(By.id("email")).sendKeys("acmereg@registry.example");
driver.findElement(By.id("password")).sendKeys("StRoNgPaSsWoRd");
driver.diffPage("formFilled");
driver.findElement(By.id("submit-button")).click();
driver.waitForElement(By.tagName("h1"));
driver.diffPage("oteResult");
}
@Test
public void get_admin_fails_badEmail() throws Throwable {
server.setIsAdmin(true);
driver.manage().window().setSize(new Dimension(1200, 2000));
driver.get(server.getUrl("/registrar-ote-setup"));
driver.waitForElement(By.tagName("h1"));
driver.findElement(By.id("clientId")).sendKeys("acmereg");
driver.findElement(By.id("email")).sendKeys("bad email");
driver.findElement(By.id("submit-button")).click();
driver.waitForElement(By.tagName("h1"));
driver.diffPage("oteResultFailed");
}
}