Skip to content

Commit

Permalink
Fix for #736: Expect response code 200 for Selenium containers versio…
Browse files Browse the repository at this point in the history
…n >= 3 (#760)

* Fix for #736: Expect response code 200 for Selenium containers version 3
onwards

* Fix for #736: get used Selenium version from classpath and extracted
logic to dedicated method

* Inlined expected response code

* Removed unnecessary line break
  • Loading branch information
georgwolf authored and lordofthejars committed Jul 18, 2017
1 parent 9fa4714 commit 7867a24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,28 @@ private static void setDefaultSeleniumCubeProperties(CubeContainer cubeContainer

Await await = new Await();
await.setStrategy("http");
// Doing an http request to selenium node returns a 403 if Jetty is up and running
await.setResponseCode(403);
await.setResponseCode(getSeleniumExpectedResponseCode());
await.setUrl("http://dockerHost:" + SELENIUM_BOUNDED_PORT);

cubeContainer.setAwait(await);

cubeContainer.setKillContainer(true);
}

private static int getSeleniumExpectedResponseCode(){
// Selenium from 3.x onwards returns 200 if started
int expectedResponseCode = 200;
String seleniumVersion = SeleniumVersionExtractor.fromClassPath();
if(seleniumVersion.matches("[0-9]+\\.?.*")){
int seleniumMajorVersion = Integer.parseInt(seleniumVersion.substring(0, seleniumVersion.indexOf('.')));
if(seleniumMajorVersion < 3){
// Doing an http request to selenium node returns a 403 if Jetty is up and running for Selenium < 3
expectedResponseCode = 403;
}
}
return expectedResponseCode;
}

public CubeContainer getSeleniumContainer() {
return seleniumContainer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void shouldCreateContainerForFirefox() {
assertThat(firefox.getBrowser(), is("firefox"));
assertThat(firefox.getSeleniumContainer().getImage().toString(), is("selenium/standalone-firefox-debug:2.53.0"));
assertThat(firefox.getSeleniumContainer().getPortBindings(), hasItem(PortBinding.valueOf("14444->4444")));
assertThat(firefox.getSeleniumContainer().getAwait().getResponseCode(), is(403));
}

@Test
Expand All @@ -78,5 +79,6 @@ public void shouldCreateContainerForChrome() {
assertThat(firefox.getBrowser(), is("chrome"));
assertThat(firefox.getSeleniumContainer().getImage().toString(), is("selenium/standalone-chrome-debug:2.53.0"));
assertThat(firefox.getSeleniumContainer().getPortBindings(), hasItem(PortBinding.valueOf("14444->4444")));
assertThat(firefox.getSeleniumContainer().getAwait().getResponseCode(), is(403));
}
}

0 comments on commit 7867a24

Please sign in to comment.