Skip to content

Commit

Permalink
Account for hyphens
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremias Roessler committed Oct 24, 2019
1 parent 84bffbc commit 3dd399a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/de/retest/web/selenium/TestHealer.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private WebElement findElementByCssSelector( final ByCssSelector by ) {
actualElement = de.retest.web.selenium.By.findElementByAttribute( lastExpectedState, lastActualState, ID,
selector.substring( 1 ) );
}
if ( selector.matches( "^[a-zA-Z]*" ) ) {
if ( selector.matches( "^[a-z\\-A-Z]*" ) ) {
actualElement = de.retest.web.selenium.By.findElementByAttribute( lastExpectedState, lastActualState, TYPE,
selector );
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/de/retest/web/selenium/TestHealerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ public void ByCssSelector_using_tag_should_redirect() {
assertThat( findElement( By.cssSelector( "div" ), wrapped ) ).isEqualTo( resultMarker );
}

@Test
public void ByCssSelector_using_tag_with_hyphen_should_redirect() {
final RecheckDriver wrapped = mock( RecheckDriver.class );
final AutocheckingWebElement resultMarker = mock( AutocheckingWebElement.class );

final RootElement state = mock( RootElement.class );
when( wrapped.getLastExpectedState() ).thenReturn( state );
when( wrapped.getLastActualState() ).thenReturn( state );

final String xpath = "html[1]/ytd-grid-video-renderer[1]";
final IdentifyingAttributes identifying =
IdentifyingAttributes.create( fromString( xpath ), "ytd-grid-video-renderer" );
final Element element = create( "id", state, identifying, new MutableAttributes().immutable() );
when( state.getContainedElements() ).thenReturn( Collections.singletonList( element ) );
when( wrapped.findElement( By.xpath( xpath ) ) ).thenReturn( resultMarker );

// assertThat( By.cssSelector( "div" ).matches( element ) ).isTrue();
assertThat( findElement( By.cssSelector( "ytd-grid-video-renderer" ), wrapped ) ).isEqualTo( resultMarker );
}

@Test
public void ByCssSelector_matches_elements_with_given_class() {
final RecheckDriver wrapped = mock( RecheckDriver.class );
Expand Down

0 comments on commit 3dd399a

Please sign in to comment.