For the first part of your question, you can add the borders without changing your markup generation by adding a simple css rule:
tr {
border-bottom: solid 1px black;
}
There is an overview about styling tables in general via both about.com and w3c schools
Note that you'll also need to set the border-collapse: collapse;
css attribute on the table.
I've put an example jsFiddle up for you.
You can place the CSS rule in your CSS section (note I've also added the border-collapse
):
<style type="text/css">
tr {
border-bottom: solid 1px black;
}
.float-left{
float:left;
border-style:solid;
border-width:2px;
border-color:Black;
border-collapse: collapse;
}
</style>
You could also consider removing the float-left css attribute and just change .float-left
to be table
to further simplify your code.
For the second part of your question:
and add a hyperlink to each of the values in the table at run time
You can simply use the HtmlAnchorClass.
In effect, a simple example is:
HtmlAnchor htmlanchor = new HtmlAnchor();
htmlanchor.HRef = "http://www.linkurl.com";
htmlanchor.InnerText = "My Link Text";
//Add it to a cell
cell.Controls.Add(htmlanchor);
This will add a hyperlink to your cell.
You may also want to consider using the ASP Repeater Control or the DataGrid control as each of these give you the option to template your markup.
Finally this is what I tried and it worked.
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>2.2.3</version>
<scope>test</scope>
</dependency>-->
</dependencies>
src/test/resources (manual download of exe required)
chromedriver.exe
BaseSeleniumTests.java
public abstract class BaseSeleniumTests {
private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
protected WebDriver driver;
@Before
public void setUp() {
String driverFile = findFile();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(driverFile))
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
options.addArguments("--headless");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.merge(capabilities);
this.driver = new ChromeDriver(service, options);
}
private String findFile() {
ClassLoader classLoader = getClass().getClassLoader();
URL url = classLoader.getResource(CHROMEDRIVER_EXE);
return url.getFile();
}
@After
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
GoogleSearchPageTraditionalSeleniumTests.java
@RunWith(SpringRunner.class)
@SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {
@Test
public void getSearchPage() {
this.driver.get("https://www.google.com");
WebElement element = this.driver.findElement(By.name("q"));
assertNotNull(element);
}
}
Best Answer
Another option might be to use REST Assured, a Java DSL for testing REST services. It allows you to write unit style tests with little boilerplate code for both XML and JSON. Additionally, it provides more advanced features like authentication, XSD / DTD validation, response codes, cookies, etc. More information is available at their usage page.
Disclaimer: REST Assured is an open source project initiated by a colleague of mine.