List of usage examples for org.openqa.selenium By name
public static By name(String name)
From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java
License:Apache License
@Test public void testOrder() { // Open the home page open("/");// w w w .j a v a2 s . c om assertThat(title()).isEqualTo("JPetStore Demo"); // Move to the top page $(By.linkText("Enter the Store")).click(); $(By.id("WelcomeContent")).shouldBe(text("")); // Move to sign in page & sign $(By.linkText("Sign In")).click(); $(By.name("username")).val("j2ee"); $(By.name("password")).val("j2ee"); $(By.id("login")).click(); $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("ABC")); // Search items $(By.name("keywords")).val("fish"); $(By.id("searchProducts")).click(); $$(By.cssSelector("#Catalog table tr")).shouldHaveSize(3); // Select item $(By.linkText("Fresh Water fish from China")).click(); $(By.cssSelector("#Catalog h2")).shouldBe(text("Goldfish")); // Add a item to the cart $(By.linkText("Add to Cart")).click(); $(By.cssSelector("#Catalog h2")).shouldBe(text("Shopping Cart")); // Checkout cart items $(By.linkText("Proceed to Checkout")).click(); assertThat(title()).isEqualTo("JPetStore Demo"); // Input card information & Confirm order information $(By.name("creditCard")).val("9999999999"); $(By.name("expiryDate")).val("04/2020"); $(By.name("continue")).click(); $(By.id("confirmMessage")).shouldBe(text("Please confirm the information below and then press submit...")); // Submit order $(By.id("order")).click(); $(By.cssSelector(".messages li")).shouldBe(text("Thank you, your order has been submitted.")); String orderId = $(By.id("orderId")).text(); // Show profile page $(By.linkText("My Account")).click(); $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information")); // Show orders $(By.linkText("My Orders")).click(); $(By.cssSelector("#Content h2")).shouldBe(text("My Orders")); // Show order detail $(By.linkText(orderId)).click(); assertThat($(By.id("orderId")).text()).isEqualTo(orderId); // Sign out $(By.linkText("Sign Out")).click(); $(By.id("WelcomeContent")).shouldBe(text("")); }
From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java
License:Apache License
@Test public void testUpdateProfile() { // Open the home page open("/");/*from ww w . ja v a2 s . co m*/ assertThat(title()).isEqualTo("JPetStore Demo"); // Move to the top page $(By.linkText("Enter the Store")).click(); $(By.id("WelcomeContent")).shouldBe(text("")); // Move to sign in page & sign $(By.linkText("Sign In")).click(); $(By.name("username")).val("j2ee"); $(By.name("password")).val("j2ee"); $(By.id("login")).click(); $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("ABC")); // Show profile page $(By.linkText("My Account")).click(); $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information")); $$(By.cssSelector("#Catalog table td")).get(1).shouldBe(text("j2ee")); // Edit account $(By.id("save")).click(); $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information")); $$(By.cssSelector("#Catalog table td")).get(1).shouldBe(text("j2ee")); }
From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java
License:Apache License
@Test public void testRegistrationUser() { // Open the home page open("/");// w w w .j a v a 2 s . c om assertThat(title()).isEqualTo("JPetStore Demo"); // Move to the top page $(By.linkText("Enter the Store")).click(); $(By.id("WelcomeContent")).shouldBe(text("")); // Move to sign in page & sign $(By.linkText("Sign In")).click(); $(By.cssSelector("#Catalog p")).shouldBe(text("Please enter your username and password.")); // Move to use registration page $(By.linkText("Register Now!")).click(); $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information")); // Create a new user String userId = String.valueOf(System.currentTimeMillis()); $(By.name("username")).val(userId); $(By.name("password")).val("password"); $(By.name("repeatedPassword")).val("password"); $(By.name("firstName")).val("Jon"); $(By.name("lastName")).val("MyBatis"); $(By.name("email")).val("jon.mybatis@test.com"); $(By.name("phone")).val("09012345678"); $(By.name("address1")).val("Address1"); $(By.name("address2")).val("Address2"); $(By.name("city")).val("Minato-Ku"); $(By.name("state")).val("Tokyo"); $(By.name("zip")).val("0001234"); $(By.name("country")).val("Japan"); $(By.name("languagePreference")).selectOption("Japanese"); $(By.name("favouriteCategoryId")).selectOption("CATS"); $(By.name("listOption")).setSelected(true); $(By.name("bannerOption")).setSelected(true); $(By.id("save")).click(); $(By.cssSelector(".messages li")).shouldBe(text("Your account has been created. Please try login !!")); // Move to sign in page & sign $(By.name("username")).val(userId); $(By.name("password")).val("password"); $(By.id("login")).click(); $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("Jon")); }
From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java
License:Apache License
@Test public void testViewCart() { // Open the home page open("/");/* w w w . ja v a 2 s . co m*/ assertThat(title()).isEqualTo("JPetStore Demo"); // Move to the top page $(By.linkText("Enter the Store")).click(); $(By.id("WelcomeContent")).shouldBe(text("")); // Move to cart $(By.name("img_cart")).click(); $(By.cssSelector("#Catalog h2")).shouldBe(text("Shopping Cart")); }
From source file:com.lazerycode.ebselen.handlers.locatorhandler.AutoLocatorTest.java
License:Apache License
@Test public void givenANameLocatorCodeReturnsCorrectType() throws Exception { assertThat(loc.autoLocator("name=foo"), is(equalTo(By.name("foo")))); }
From source file:com.lazerycode.ebselen.handlers.LocatorHandler.java
License:Apache License
/** * Take a locator and work out what sort of By.xxx should be used * * @param locator - locator to evaluate//w ww . j a v a 2s . com * @return By - a By format that sky.sns.selenium 2 can utilise */ public By autoLocator(String locator) { switch (getLocatorType(locator)) { case XPATH: if (locator.startsWith("xpath=")) { locator = locator.split("=", 2)[1]; } return By.xpath(locator); case CSS_SELECTOR: if (locator.startsWith("css=")) { locator = locator.split("=", 2)[1]; } return By.cssSelector(locator); case ID: if (locator.startsWith("id=")) { locator = locator.split("=", 2)[1]; } return By.id(locator); case NAME: if (locator.startsWith("name=")) { locator = locator.split("=", 2)[1]; } return By.name(locator); case CLASS_NAME: if (locator.startsWith("class=")) { locator = locator.split("=", 2)[1]; } return By.className(locator); case TAG_NAME: if (locator.startsWith("tag=")) { locator = locator.split("=", 2)[1]; } return By.tagName(locator); case LINK_TEXT: if (locator.startsWith("link=")) { locator = locator.split("=", 2)[1]; } return By.linkText(locator); default: if (locator.startsWith("dom:name=")) { locator = locator.split("=", 2)[1]; return By.xpath("//form[@name='" + locator + "']"); } else if (locator.startsWith("dom:index=")) { locator = locator.split("=", 2)[1]; return By.xpath("(//form)[" + locator + "]"); } } return null; }
From source file:com.lemon.web.functional.gui.RegisterFT.java
License:Apache License
@Test public void register() { // // w w w . j a v a 2 s. c o m s.open("/logout"); s.click(By.linkText("")); s.type(By.id("loginName"), "user2"); s.type(By.id("name"), "Kevin"); s.type(By.id("plainPassword"), "user2"); s.type(By.id("confirmPassword"), "user2"); s.click(By.id("submit_btn")); // s.waitForTitleContains(""); assertThat(s.getValue(By.name("username"))).isEqualTo("user2"); s.type(By.name("password"), "user2"); s.click(By.id("submit_btn")); // ? s.waitForTitleContains("?"); // s.open("/logout"); }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
public static By getBy(String locator) { if (locator.startsWith("//")) { return By.xpath(locator); } else if (locator.startsWith("class=")) { locator = locator.substring(6);// w w w. ja v a2 s . c o m return By.className(locator); } else if (locator.startsWith("css=")) { locator = locator.substring(4); return By.cssSelector(locator); } else if (locator.startsWith("link=")) { locator = locator.substring(5); return By.linkText(locator); } else if (locator.startsWith("name=")) { locator = locator.substring(5); return By.name(locator); } else if (locator.startsWith("tag=")) { locator = locator.substring(4); return By.tagName(locator); } else if (locator.startsWith("xpath=") || locator.startsWith("xPath=")) { locator = locator.substring(6); return By.xpath(locator); } else { return By.id(locator); } }
From source file:com.linagora.obm.ui.page.DeleteUserPage.java
License:Open Source License
public boolean deletionSucceeded() { try {/*from w w w. j av a 2 s . c o m*/ waitAndTestElementPresence(By.name("displayMessageOk")); return true; } catch (org.openqa.selenium.TimeoutException e) { return false; } }
From source file:com.linagora.obm.ui.page.FindUserPage.java
License:Open Source License
public void findUserByLogin(String userLogin) { driver.findElement(By.name("tf_login")).sendKeys(userLogin); driver.findElement(By.name("submit")).click(); }