How to use ConverterFunctions class of org.openqa.selenium.devtools package

Best Selenium code snippet using org.openqa.selenium.devtools.ConverterFunctions

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.devtools.v99;
19
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableMap;
22import org.openqa.selenium.devtools.Command;
23import org.openqa.selenium.devtools.ConverterFunctions;
24import org.openqa.selenium.devtools.Event;
25import org.openqa.selenium.devtools.idealized.browser.model.BrowserContextID;
26import org.openqa.selenium.devtools.idealized.target.model.SessionID;
27import org.openqa.selenium.devtools.idealized.target.model.TargetID;
28import org.openqa.selenium.devtools.v99.target.Target;
29import org.openqa.selenium.devtools.v99.target.model.TargetInfo;
30import org.openqa.selenium.json.JsonInput;
31import org.openqa.selenium.json.TypeToken;
32
33import java.util.List;
34import java.util.Optional;
35import java.util.function.Function;
36
37public class V99Target implements org.openqa.selenium.devtools.idealized.target.Target {
38  @Override
39  public Command<Void> detachFromTarget(Optional<SessionID> sessionId, Optional<TargetID> targetId) {
40    return Target.detachFromTarget(
41      sessionId.map(id -> new org.openqa.selenium.devtools.v99.target.model.SessionID(id.toString())),
42      targetId.map(id -> new org.openqa.selenium.devtools.v99.target.model.TargetID(id.toString())));
43  }
44
45  @Override
46  public Command<List<org.openqa.selenium.devtools.idealized.target.model.TargetInfo>> getTargets() {
47    Function<JsonInput, List<TargetInfo>> mapper = ConverterFunctions.map(
48      "targetInfos",
49      new TypeToken<List<TargetInfo>>() {}.getType());
50
51    return new Command<>(
52      Target.getTargets().getMethod(),
53      ImmutableMap.of(),
54      input -> {
55        List<TargetInfo> infos = mapper.apply(input);
56        return infos.stream()
57          .map(info -> new org.openqa.selenium.devtools.idealized.target.model.TargetInfo(
58            new TargetID(info.getTargetId().toString()),
59            info.getType(),
60            info.getTitle(),
61            info.getUrl(),
62            info.getAttached(),
63            info.getOpenerId().map(id -> new TargetID(id.toString())),
64            info.getBrowserContextId().map(id -> new BrowserContextID(id.toString()))
65          ))
66          .collect(ImmutableList.toImmutableList());
67      });
68  }
69
70  @Override
71  public Command<SessionID> attachToTarget(TargetID targetId) {
72    Function<JsonInput, org.openqa.selenium.devtools.v99.target.model.SessionID> mapper =
73      ConverterFunctions.map("sessionId", org.openqa.selenium.devtools.v99.target.model.SessionID.class);
74
75    return new Command<>(
76      "Target.attachToTarget",
77      ImmutableMap.of(
78        "targetId", new org.openqa.selenium.devtools.v99.target.model.TargetID(targetId.toString()),
79        "flatten", true),
80      input -> {
81        org.openqa.selenium.devtools.v99.target.model.SessionID id = mapper.apply(input);
82        return new SessionID(id.toString());
83      });
84  }
85
86  @Override
87  public Command<Void> setAutoAttach() {
88    return Target.setAutoAttach(true, false, Optional.of(true));
89  }
90
91  @Override
92  public Event<TargetID> detached() {
93    return new Event<>(
94      "Target.detachedFromTarget",
95      input -> {
96        Function<JsonInput, org.openqa.selenium.devtools.v99.target.model.TargetID> converter =
97          ConverterFunctions.map("targetId", org.openqa.selenium.devtools.v99.target.model.TargetID.class);
98        return new TargetID(converter.apply(input).toString());
99      }
100    );
101  }
102}
103
Full Screen
copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.devtools.v85;
19
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableMap;
22import org.openqa.selenium.devtools.Command;
23import org.openqa.selenium.devtools.ConverterFunctions;
24import org.openqa.selenium.devtools.Event;
25import org.openqa.selenium.devtools.idealized.browser.model.BrowserContextID;
26import org.openqa.selenium.devtools.idealized.target.model.SessionID;
27import org.openqa.selenium.devtools.idealized.target.model.TargetID;
28import org.openqa.selenium.devtools.v85.target.Target;
29import org.openqa.selenium.devtools.v85.target.model.TargetInfo;
30import org.openqa.selenium.json.JsonInput;
31import org.openqa.selenium.json.TypeToken;
32
33import java.util.List;
34import java.util.Optional;
35import java.util.function.Function;
36
37public class V85Target implements org.openqa.selenium.devtools.idealized.target.Target {
38  @Override
39  public Command<Void> detachFromTarget(Optional<SessionID> sessionId, Optional<TargetID> targetId) {
40    return Target.detachFromTarget(
41      sessionId.map(id -> new org.openqa.selenium.devtools.v85.target.model.SessionID(id.toString())),
42      targetId.map(id -> new org.openqa.selenium.devtools.v85.target.model.TargetID(id.toString())));
43  }
44
45  @Override
46  public Command<List<org.openqa.selenium.devtools.idealized.target.model.TargetInfo>> getTargets() {
47    Function<JsonInput, List<TargetInfo>> mapper = ConverterFunctions.map(
48      "targetInfos",
49      new TypeToken<List<TargetInfo>>() {}.getType());
50
51    return new Command<>(
52      Target.getTargets().getMethod(),
53      ImmutableMap.of(),
54      input -> {
55        List<TargetInfo> infos = mapper.apply(input);
56        return infos.stream()
57          .map(info -> new org.openqa.selenium.devtools.idealized.target.model.TargetInfo(
58            new TargetID(info.getTargetId().toString()),
59            info.getType(),
60            info.getTitle(),
61            info.getUrl(),
62            info.getAttached(),
63            info.getOpenerId().map(id -> new TargetID(id.toString())),
64            info.getBrowserContextId().map(id -> new BrowserContextID(id.toString()))
65          ))
66          .collect(ImmutableList.toImmutableList());
67      });
68  }
69
70  @Override
71  public Command<SessionID> attachToTarget(TargetID targetId) {
72    Function<JsonInput, org.openqa.selenium.devtools.v85.target.model.SessionID> mapper =
73      ConverterFunctions.map("sessionId", org.openqa.selenium.devtools.v85.target.model.SessionID.class);
74
75    return new Command<>(
76      "Target.attachToTarget",
77      ImmutableMap.of(
78        "targetId", new org.openqa.selenium.devtools.v85.target.model.TargetID(targetId.toString()),
79        "flatten", true),
80      input -> {
81        org.openqa.selenium.devtools.v85.target.model.SessionID id = mapper.apply(input);
82        return new SessionID(id.toString());
83      });
84  }
85
86  @Override
87  public Command<Void> setAutoAttach() {
88    return Target.setAutoAttach(true, false, Optional.of(true));
89  }
90
91  @Override
92  public Event<TargetID> detached() {
93    return new Event<>(
94      "Target.detachedFromTarget",
95      input -> {
96        Function<JsonInput, org.openqa.selenium.devtools.v85.target.model.TargetID> converter =
97          ConverterFunctions.map("targetId", org.openqa.selenium.devtools.v85.target.model.TargetID.class);
98        return new TargetID(converter.apply(input).toString());
99      }
100    );
101  }
102}
103
Full Screen
copy
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18package org.openqa.selenium.devtools.v97;
19
20import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableMap;
22import org.openqa.selenium.devtools.Command;
23import org.openqa.selenium.devtools.ConverterFunctions;
24import org.openqa.selenium.devtools.Event;
25import org.openqa.selenium.devtools.idealized.browser.model.BrowserContextID;
26import org.openqa.selenium.devtools.idealized.target.model.SessionID;
27import org.openqa.selenium.devtools.idealized.target.model.TargetID;
28import org.openqa.selenium.devtools.v97.target.Target;
29import org.openqa.selenium.devtools.v97.target.model.TargetInfo;
30import org.openqa.selenium.json.JsonInput;
31import org.openqa.selenium.json.TypeToken;
32
33import java.util.List;
34import java.util.Optional;
35import java.util.function.Function;
36
37public class V97Target implements org.openqa.selenium.devtools.idealized.target.Target {
38  @Override
39  public Command<Void> detachFromTarget(Optional<SessionID> sessionId, Optional<TargetID> targetId) {
40    return Target.detachFromTarget(
41      sessionId.map(id -> new org.openqa.selenium.devtools.v97.target.model.SessionID(id.toString())),
42      targetId.map(id -> new org.openqa.selenium.devtools.v97.target.model.TargetID(id.toString())));
43  }
44
45  @Override
46  public Command<List<org.openqa.selenium.devtools.idealized.target.model.TargetInfo>> getTargets() {
47    Function<JsonInput, List<TargetInfo>> mapper = ConverterFunctions.map(
48      "targetInfos",
49      new TypeToken<List<TargetInfo>>() {}.getType());
50
51    return new Command<>(
52      Target.getTargets().getMethod(),
53      ImmutableMap.of(),
54      input -> {
55        List<TargetInfo> infos = mapper.apply(input);
56        return infos.stream()
57          .map(info -> new org.openqa.selenium.devtools.idealized.target.model.TargetInfo(
58            new TargetID(info.getTargetId().toString()),
59            info.getType(),
60            info.getTitle(),
61            info.getUrl(),
62            info.getAttached(),
63            info.getOpenerId().map(id -> new TargetID(id.toString())),
64            info.getBrowserContextId().map(id -> new BrowserContextID(id.toString()))
65          ))
66          .collect(ImmutableList.toImmutableList());
67      });
68  }
69
70  @Override
71  public Command<SessionID> attachToTarget(TargetID targetId) {
72    Function<JsonInput, org.openqa.selenium.devtools.v97.target.model.SessionID> mapper =
73      ConverterFunctions.map("sessionId", org.openqa.selenium.devtools.v97.target.model.SessionID.class);
74
75    return new Command<>(
76      "Target.attachToTarget",
77      ImmutableMap.of(
78        "targetId", new org.openqa.selenium.devtools.v97.target.model.TargetID(targetId.toString()),
79        "flatten", true),
80      input -> {
81        org.openqa.selenium.devtools.v97.target.model.SessionID id = mapper.apply(input);
82        return new SessionID(id.toString());
83      });
84  }
85
86  @Override
87  public Command<Void> setAutoAttach() {
88    return Target.setAutoAttach(true, false, Optional.of(true));
89  }
90
91  @Override
92  public Event<TargetID> detached() {
93    return new Event<>(
94      "Target.detachedFromTarget",
95      input -> {
96        Function<JsonInput, org.openqa.selenium.devtools.v97.target.model.TargetID> converter =
97          ConverterFunctions.map("targetId", org.openqa.selenium.devtools.v97.target.model.TargetID.class);
98        return new TargetID(converter.apply(input).toString());
99      }
100    );
101  }
102}
103
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on ConverterFunctions

    No relevant questions found for this class 😞

Most used methods in ConverterFunctions

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)