Skip to content

Commit

Permalink
Merge pull request #337 from telekom/feature/store-raw-useragent
Browse files Browse the repository at this point in the history
Feature/store raw useragent
  • Loading branch information
martingrossmann authored Aug 15, 2023
2 parents 3b948d6 + a3af0e1 commit e70574f
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SessionContext extends AbstractContext {
private Video video;
private String actualBrowserName;
private String actualBrowserVersion;
private String userAgent;
private WebDriverRequest webDriverRequest;
private URL nodeUrl;
private final Queue<MethodContext> methodContexts = new ConcurrentLinkedQueue<>();
Expand Down Expand Up @@ -120,6 +121,14 @@ public void setActualBrowserVersion(String browserVersion) {
this.actualBrowserVersion = browserVersion;
}

public Optional<String> getUserAgent() {
return Optional.ofNullable(userAgent);
}

public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

void addMethodContext(MethodContext methodContext) {
this.methodContexts.add(methodContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public interface BrowserInformation {

void parseUserAgent(String userAgent);

/**
* Gets the user agent string of used browser.
*
* @return the raw user agent string
*/
String getUserAgent();

/**
* Gets the browser name of the test run.
*
Expand All @@ -37,4 +44,6 @@ public interface BrowserInformation {
* @return the browser version.
*/
String getBrowserVersion();


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class UapBrowserInformation implements BrowserInformation, Loggable {
private static Parser userAgentAnalyzer;
private Client client;

private String userAgent;

public UapBrowserInformation() {
try {
userAgentAnalyzer = new Parser();
Expand All @@ -47,9 +49,15 @@ public UapBrowserInformation() {
*/
@Override
public void parseUserAgent(String userAgent) {
this.userAgent = userAgent;
client = userAgentAnalyzer.parse(userAgent);
}

@Override
public String getUserAgent() {
return this.userAgent;
}

@Override
public String getBrowserName() {
return client.userAgent.family;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public static EventFiringWebDriver getWebDriver(final WebDriverRequest webDriver

if (!sessionContext.getActualBrowserName().isPresent()) {
BrowserInformation browserInformation = WebDriverManagerUtils.getBrowserInformation(newRawWebDriver);
sessionContext.setUserAgent(browserInformation.getUserAgent());
sessionContext.setActualBrowserName(browserInformation.getBrowserName());
sessionContext.setActualBrowserVersion(browserInformation.getBrowserVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public void testUiElement() throws Exception {
public void testTapCapabilities() throws Exception {
DesktopWebDriverRequest request = new DesktopWebDriverRequest();
request.setBaseUrl("http://google.de");
request.setWebDriverMode(WebDriverMode.local);
request.setBrowser(Browsers.phantomjs);

/*
create caps
Expand All @@ -74,7 +72,7 @@ public void testTapCapabilities() throws Exception {
// start session
WebDriver driver = WEB_DRIVER_MANAGER.getWebDriver(request);

SessionContext sessionContext = WebDriverSessionsManager.getSessionContext(driver).get();
SessionContext sessionContext = WEB_DRIVER_MANAGER.getSessionContext(driver).get();
Map<String, Object> sessionCapabilities = sessionContext.getWebDriverRequest().getCapabilities();

Assert.assertEquals(sessionCapabilities.get("projectId"), caps.getCapability("projectId"), "EndPoint Capability is set");
Expand All @@ -84,8 +82,6 @@ public void testTapCapabilities() throws Exception {
public void testFailing() throws Exception {
DesktopWebDriverRequest request = new DesktopWebDriverRequest();
request.setBaseUrl("http://google.de");
// request.setWebDriverMode(WebDriverMode.local);
// request.setBrowser(Browsers.phantomjs);

WEB_DRIVER_MANAGER.getWebDriver(request);
Assert.assertTrue(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ public SessionContext.Builder buildSessionContext(eu.tsystems.mms.tic.testframew

sessionContext.getActualBrowserName().ifPresent(builder::setBrowserName);
sessionContext.getActualBrowserVersion().ifPresent(builder::setBrowserVersion);
sessionContext.getUserAgent().ifPresent(builder::setUserAgent);
builder.setCapabilities(jsonEncoder.toJson(sessionContext.getWebDriverRequest().getCapabilities()));
sessionContext.getWebDriverRequest().getServerUrl().ifPresent(url -> builder.setServerUrl(url.toString()));
sessionContext.getNodeInfo().ifPresent(nodeInfo -> builder.setNodeUrl(nodeInfo.toString()));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e70574f

Please sign in to comment.