Browse Source

Update testcontainers and selenium (#8218)

Lauri Tulmin 1 year ago
parent
commit
856d521f0a

+ 1 - 1
dependencyManagement/build.gradle.kts

@@ -35,7 +35,7 @@ val DEPENDENCY_BOMS = listOf(
   "io.opentelemetry:opentelemetry-bom:${otelSdkVersion}",
   "io.opentelemetry:opentelemetry-bom-alpha:${otelSdkVersion}-alpha",
   "org.junit:junit-bom:5.9.2",
-  "org.testcontainers:testcontainers-bom:1.17.6",
+  "org.testcontainers:testcontainers-bom:1.18.0",
   "org.spockframework:spock-bom:2.4-M1-groovy-4.0"
 )
 

+ 16 - 6
instrumentation/aws-sdk/aws-sdk-1.11/javaagent/src/test/groovy/AwsConnector.groovy

@@ -3,6 +3,10 @@
  * SPDX-License-Identifier: Apache-2.0
  */
 
+import com.amazonaws.auth.AWSCredentialsProvider
+import com.amazonaws.auth.AWSStaticCredentialsProvider
+import com.amazonaws.auth.BasicAWSCredentials
+import com.amazonaws.client.builder.AwsClientBuilder
 import com.amazonaws.regions.Regions
 import com.amazonaws.services.s3.AmazonS3Client
 import com.amazonaws.services.s3.model.BucketNotificationConfiguration
@@ -45,24 +49,30 @@ class AwsConnector {
     awsConnector.localstack.start()
     awsConnector.localstack.followOutput(new Slf4jLogConsumer(LoggerFactory.getLogger("test")))
 
+    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsConnector.localstack .getAccessKey(), awsConnector.localstack.getSecretKey()))
+
     awsConnector.sqsClient = AmazonSQSAsyncClient.asyncBuilder()
-      .withEndpointConfiguration(awsConnector.localstack.getEndpointConfiguration(LocalStackContainer.Service.SQS))
-      .withCredentials(awsConnector.localstack.getDefaultCredentialsProvider())
+      .withEndpointConfiguration(getEndpointConfiguration(awsConnector.localstack, LocalStackContainer.Service.SQS))
+      .withCredentials(credentialsProvider)
       .build()
 
     awsConnector.s3Client = AmazonS3Client.builder()
-      .withEndpointConfiguration(awsConnector.localstack.getEndpointConfiguration(LocalStackContainer.Service.S3))
-      .withCredentials(awsConnector.localstack.getDefaultCredentialsProvider())
+      .withEndpointConfiguration(getEndpointConfiguration(awsConnector.localstack, LocalStackContainer.Service.S3))
+      .withCredentials(credentialsProvider)
       .build()
 
     awsConnector.snsClient = AmazonSNSAsyncClient.asyncBuilder()
-      .withEndpointConfiguration(awsConnector.localstack.getEndpointConfiguration(LocalStackContainer.Service.SNS))
-      .withCredentials(awsConnector.localstack.getDefaultCredentialsProvider())
+      .withEndpointConfiguration(getEndpointConfiguration(awsConnector.localstack, LocalStackContainer.Service.SNS))
+      .withCredentials(credentialsProvider)
       .build()
 
     return awsConnector
   }
 
+  static AwsClientBuilder.EndpointConfiguration getEndpointConfiguration(LocalStackContainer localstack, LocalStackContainer.Service service) {
+    return new AwsClientBuilder.EndpointConfiguration(localstack.getEndpointOverride(service).toString(), localstack.getRegion())
+  }
+
   static liveAws() {
     AwsConnector awsConnector = new AwsConnector()
 

+ 1 - 1
instrumentation/gwt-2.0/javaagent/build.gradle.kts

@@ -49,7 +49,7 @@ dependencies {
   testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent"))
 
   testImplementation("org.testcontainers:selenium")
-  testImplementation("org.seleniumhq.selenium:selenium-java:3.141.59")
+  testImplementation("org.seleniumhq.selenium:selenium-java:4.8.3")
 
   testImplementation("org.eclipse.jetty:jetty-webapp:9.4.35.v20201120")
 }

+ 10 - 8
instrumentation/gwt-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/gwt/GwtTest.java

@@ -17,7 +17,7 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
 import java.io.File;
 import java.io.IOException;
 import java.net.URI;
-import java.util.concurrent.TimeUnit;
+import java.time.Duration;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
+import org.openqa.selenium.By;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.openqa.selenium.remote.RemoteWebDriver;
 import org.slf4j.Logger;
@@ -92,8 +93,9 @@ class GwtTest {
   }
 
   RemoteWebDriver getDriver() {
-    RemoteWebDriver driver = browser.getWebDriver();
-    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
+    RemoteWebDriver driver =
+        new RemoteWebDriver(browser.getSeleniumAddress(), new ChromeOptions(), false);
+    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
     return driver;
   }
 
@@ -104,7 +106,7 @@ class GwtTest {
     // fetch the test page
     driver.get(address.resolve("greeting.html").toString());
 
-    driver.findElementByClassName("greeting.button");
+    driver.findElement(By.className("greeting.button"));
     testing.waitAndAssertSortedTraces(
         orderByRootSpanName("GET " + getContextPath() + "/*", "GET"),
         trace -> {
@@ -140,8 +142,8 @@ class GwtTest {
     testing.clearData();
 
     // click a button to trigger calling java code
-    driver.findElementByClassName("greeting.button").click();
-    assertEquals(driver.findElementByClassName("message.received").getText(), "Hello, Otel");
+    driver.findElement(By.className("greeting.button")).click();
+    assertEquals(driver.findElement(By.className("message.received")).getText(), "Hello, Otel");
 
     testing.waitAndAssertTraces(
         trace ->
@@ -166,8 +168,8 @@ class GwtTest {
     testing.clearData();
 
     // click a button to trigger calling java code
-    driver.findElementByClassName("error.button").click();
-    assertEquals(driver.findElementByClassName("error.received").getText(), "Error");
+    driver.findElement(By.className("error.button")).click();
+    assertEquals(driver.findElement(By.className("error.received")).getText(), "Error");
 
     testing.waitAndAssertTraces(
         trace ->

+ 1 - 1
instrumentation/vaadin-14.2/testing/build.gradle.kts

@@ -7,5 +7,5 @@ dependencies {
 
   api("org.testcontainers:selenium")
   implementation(project(":testing-common"))
-  implementation("org.seleniumhq.selenium:selenium-java:3.141.59")
+  implementation("org.seleniumhq.selenium:selenium-java:4.8.3")
 }

+ 10 - 9
instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadinTest.java

@@ -24,14 +24,15 @@ import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.time.Duration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
+import org.openqa.selenium.By;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.openqa.selenium.remote.RemoteWebDriver;
 import org.slf4j.Logger;
@@ -76,7 +77,7 @@ public abstract class AbstractVaadinTest
     Testcontainers.exposeHostPorts(port);
 
     browser =
-        new BrowserWebDriverContainer<>("selenium/standalone-chrome:111.0")
+        new BrowserWebDriverContainer<>()
             .withCapabilities(new ChromeOptions())
             .withLogConsumer(new Slf4jLogConsumer(logger));
     browser.start();
@@ -133,18 +134,18 @@ public abstract class AbstractVaadinTest
     // In development mode ui javascript is compiled when application starts
     // this involves downloading and installing npm and a bunch of packages
     // and running webpack. Wait until all of this is done before starting test.
-    driver.manage().timeouts().implicitlyWait(3, TimeUnit.MINUTES);
+    driver.manage().timeouts().implicitlyWait(Duration.ofMinutes(3));
     driver.get(address.resolve("main").toString());
     // wait for page to load
-    driver.findElementById("main.label");
+    driver.findElement(By.id("main.label"));
     // clear traces so test would start from clean state
     testing.clearData();
 
-    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
+    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
   }
 
   private RemoteWebDriver getWebDriver() {
-    return browser.getWebDriver();
+    return new RemoteWebDriver(browser.getSeleniumAddress(), new ChromeOptions(), false);
   }
 
   abstract void assertFirstRequest();
@@ -188,16 +189,16 @@ public abstract class AbstractVaadinTest
     driver.get(address.resolve("main").toString());
 
     // wait for page to load
-    assertThat(driver.findElementById("main.label").getText()).isEqualTo("Main view");
+    assertThat(driver.findElement(By.id("main.label")).getText()).isEqualTo("Main view");
     assertFirstRequest();
 
     testing.clearData();
 
     // click a button to trigger calling java code in MainView
-    driver.findElementById("main.button").click();
+    driver.findElement(By.id("main.button")).click();
 
     // wait for page to load
-    assertThat(driver.findElementById("other.label").getText()).isEqualTo("Other view");
+    assertThat(driver.findElement(By.id("other.label")).getText()).isEqualTo("Other view");
     assertButtonClick();
 
     driver.close();