List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.java.cukes.CheckoutSteps.java
License:Apache License
@Then("^I should see order confirmation message$") public void I_should_see_order_confirmation_message() throws Throwable { new WebDriverWait(driver, 60).until(ExpectedConditions.urlContains("success")); assertEquals(driver.findElement(By.tagName("h1")).getText(), "YOUR ORDER HAS BEEN RECEIVED."); assertEquals(driver.findElement(By.tagName("h2")).getText(), "THANK YOU FOR YOUR PURCHASE!"); }
From source file:com.joyce.automation.util.prop.Prop.java
License:Apache License
/** * //from www. j a v a 2s .c o m * ??:???? * * @param elementNameInProp * ?key(eg:login.username=id>value ) * @author jiaozhongbin * @throws Exception */ public By getLocator(String elementNameInProp) { String locator = properties.getProperty(elementNameInProp); String locatorType = locator.split(Const.DEFAULT_SPLIT)[0]; String locatorValue = locator.split(Const.DEFAULT_SPLIT)[1]; try { // locatorValue = new String(locatorValue.getBytes("ISO-8859-1"), "UTF-8"); if (locatorType.toLowerCase().equals("id")) { return By.id(locatorValue); } else if (locatorType.toLowerCase().equals("xpath")) { return By.xpath(locatorValue); } else if (locatorType.toLowerCase().equals("name")) { return By.name(locatorValue); } else if (locatorType.toLowerCase().equals("classname") || locatorType.toLowerCase().equals("class")) { return By.className(locatorValue); } else if (locatorType.toLowerCase().equals("tagname") || locatorType.toLowerCase().equals("tag")) { return By.tagName(locatorValue); } else if (locatorType.toLowerCase().equals("linktext") || locatorType.toLowerCase().equals("link")) { return By.linkText(locatorValue); } else if (locatorType.toLowerCase().equals("partiallinktext")) { return By.partialLinkText(locatorValue); } else if (locatorType.toLowerCase().equals("cssselector") || locatorType.toLowerCase().equals("css")) { return By.cssSelector(locatorValue); } else log.error("locatorType?:" + locatorType); return null; } catch (IllegalArgumentException e1) { log.error("{" + locatorType + "=" + locatorValue + "}?", e1); } return null; }
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 a 2 s.c o 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")); // 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 . j a v a2 s . c o 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("/");/*from w w w .ja v a 2s . 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.lazerycode.ebselen.handlers.locatorhandler.AutoLocatorTest.java
License:Apache License
@Test public void givenATagNameLocatorCodeReturnsCorrectType() throws Exception { assertThat(loc.autoLocator("tag=div"), is(equalTo(By.tagName("div")))); }
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/*from w w w . java 2s . co m*/ * @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.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public String getBodyText() { WebElement webElement = findElement(By.tagName("body")); return webElement.getText(); }
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public boolean isTextPresent(String pattern) { WebElement webElement = findElement(By.tagName("body")); String text = webElement.getText(); return text.contains(pattern); }
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);//from ww w . ja v a 2 s . co 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); } }