This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dumiduh.utils; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.SearchContext; | |
import org.openqa.selenium.WebElement; | |
import java.util.List; | |
public class Text extends By { | |
private String searchTerm; | |
private final String XPATH = "//*[contains(text(),'%s')]"; | |
public static By containsText(String searchTerm) { | |
return new Text(searchTerm); | |
} | |
private Text(String value) { | |
this.searchTerm = value; | |
} | |
@Override | |
public List<WebElement> findElements(SearchContext context) { | |
return context.findElements(By.xpath(String.format(XPATH, searchTerm))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dumiduh.other; | |
import com.dumiduh.constants.Constants; | |
import com.dumiduh.utils.Text; | |
import com.dumiduh.utils.TestBase; | |
import org.testng.Assert; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
/*** | |
* The objective of this test is to demonstrate the use of a custom locator. | |
*/ | |
public class CustomeLocatorTest extends TestBase { | |
@BeforeClass | |
public static void setup() { | |
instantiateDriver(); | |
driver.get(Constants.DYNAMIC_LOAD); | |
} | |
@Test | |
public static void byContainsText() { | |
Assert.assertTrue(driver.findElement(Text.containsText("Powered by")).isDisplayed(), "the expected text value was not found in the html document."); | |
} | |
@AfterClass | |
public static void cleanUp() { | |
driver.quit(); | |
} | |
} |
No comments:
Post a Comment