Run Selenium automation tests on LambdaTest cloud grid
Perform automation testing on 3000+ real desktop and mobile devices online.
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.grid.data;
import org.openqa.selenium.events.Event;
import org.openqa.selenium.events.EventListener;
import org.openqa.selenium.events.EventName;
import org.openqa.selenium.internal.Require;
import java.util.function.Consumer;
public class NodeStatusEvent extends Event {
private static final EventName NODE_STATUS = new EventName("node-status");
public NodeStatusEvent(NodeStatus status) {
super(NODE_STATUS, Require.nonNull("Node status", status));
}
public static EventListener<NodeStatus> listener(Consumer<NodeStatus> handler) {
Require.nonNull("Handler", handler);
return new EventListener<NodeStatus>(NODE_STATUS, NodeStatus.class, handler);
}
}
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.grid.data;
import org.openqa.selenium.events.Event;
import org.openqa.selenium.events.EventListener;
import org.openqa.selenium.events.EventName;
import org.openqa.selenium.internal.Require;
import java.util.function.Consumer;
public class NodeAddedEvent extends Event {
private static final EventName NODE_ADDED = new EventName("node-added");
public NodeAddedEvent(NodeId nodeId) {
super(NODE_ADDED, nodeId);
}
public static EventListener<NodeId> listener(Consumer<NodeId> handler) {
Require.nonNull("Handler", handler);
return new EventListener<>(NODE_ADDED, NodeId.class, handler);
}
}
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.openqa.selenium.grid.data;
import org.openqa.selenium.events.Event;
import org.openqa.selenium.events.EventListener;
import org.openqa.selenium.events.EventName;
import org.openqa.selenium.internal.Require;
import java.util.function.Consumer;
public class NodeDrainComplete extends Event {
private static final EventName NODE_DRAIN_COMPLETE = new EventName("node-drain-complete");
public NodeDrainComplete(NodeId id) {
super(NODE_DRAIN_COMPLETE, id);
}
public static EventListener<NodeId> listener(Consumer<NodeId> handler) {
Require.nonNull("Handler", handler);
return new EventListener<>(NODE_DRAIN_COMPLETE, NodeId.class, handler);
}
}
@Component
public class AppStartupRunner implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
//some logic here
}
}
@RequiredArgsConstructor
@Component
@Slf4j
public class BeerLoader implements CommandLineRunner {
//declare
@Override
public void run(String... args) throws Exception {
//some code here
}
public classs SpringBootApplication implements CommandLineRunner{
@Override
public void run(String... arg0) throws Exception {
// write your logic here
}
}
@Bean
public CommandLineRunner commandLineRunner() {
return (args) -> System.out.println("Hello World");
}
@Component
public class MyCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("Hello World");
}
}
@Bean
@Order(1)
public CommandLineRunner commandLineRunner() {
return (args) -> System.out.println("Hello World, Order 1");
}
@Bean
@Order(2)
public CommandLineRunner commandLineRunner() {
return (args) -> System.out.println("Hello World, Order 2");
}
@EventListener(ContextRefreshedEvent.class)
public void execute() {
if(alreadyDone) {
return;
}
System.out.println("hello world");
}
@Component
public class OnStartServer implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent arg0) {
// EXECUTE YOUR CODE HERE
}
}
@Component
public class CommandLineAppStartupRunner implements CommandLineRunner {
private static final Logger logger = LoggerFactory.getLogger(CommandLineAppStartupRunner.class);
@Override
public void run(String...args) throws Exception {
logger.info("Application started with command-line arguments: {} . \n To kill this application, press Ctrl + C.", Arrays.toString(args));
}
}
@EventListener
fun doSomethingAfterStartup(event: ApplicationReadyEvent) {
System.out.println("hello world, I have just started up");
}
@Configuration
public class InitialDataConfiguration {
@PostConstruct
public void postConstruct() {
System.out.println("Started after Spring boot application !");
}
}
@Configuration
public class InitialDataConfiguration {
@Bean
CommandLineRunner runner() {
return args -> {
System.out.println("CommandLineRunner running in the UnsplashApplication class...");
};
}
}
@Bean
public SmartInitializingSingleton importProcessor() {
return () -> {
doStuff();
};
}
import org.springframework.boot.ApplicationRunner;
@Component
public class ServerInitializer implements ApplicationRunner {
@Override
public void run(ApplicationArguments applicationArguments) throws Exception {
//code goes here
}
}
@Component
public class Monitor {
@Autowired private SomeService service
@PostConstruct
public void init(){
// start your monitoring in here
}
}
@Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> {
/**
* This event is executed as late as conceivably possible to indicate that
* the application is ready to service requests.
*/
@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {
// here your code ...
return;
}
}
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
@SuppressWarnings("resource")
public static void main(final String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
context.getBean(Table.class).fillWithTestdata(); // <-- here
}
}
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() {
System.out.println("hello world, I have just started up");
}
public static void sendData(int position)
{
......
}
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
HomeFragment.sendData(position)
........
}
MyFragment extends Fragment implements CustomAdapter.EventListener {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
CustomAdapter adapter = new CustomAdapter(..., this);
}
void onEvent(int data) {
doSomething(data);
}
}
CustomAdapter extends BaseAdapter {
EventListener listener;
public interface EventListener {
void onEvent(int data);
}
public CustomAdapter(..., EventListener listener) {
this.listener = listener;
}
...
}
customAdapter = new CustomAdapter(myContext, android.R.layout.simple_list_item_1, getList, HomeFragment.this);
public CustomAdapter(Context context, int id, HomeFragment fragment) {
this.fragment = fragment;
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import java.util.Random;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* @see https://stackoverflow.com/q/3066590/230513
* 15-Mar-2011 r8 https://stackoverflow.com/questions/5274962
* 26-Mar-2013 r17 per comment
*/
public class MVCGame implements Runnable {
public static void main(String[] args) {
EventQueue.invokeLater(new MVCGame());
}
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new MainPanel());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
class MainPanel extends JPanel {
public MainPanel() {
super(new BorderLayout());
Model model = new Model();
View view = new View(model);
Control control = new Control(model, view);
JLabel label = new JLabel("Guess what color!", JLabel.CENTER);
this.add(label, BorderLayout.NORTH);
this.add(view, BorderLayout.CENTER);
this.add(control, BorderLayout.SOUTH);
}
}
/**
* Control panel
*/
class Control extends JPanel {
private Model model;
private View view;
private JButton reset = new JButton("Reset");
public Control(Model model, View view) {
this.model = model;
this.view = view;
this.add(reset);
reset.addActionListener(new ButtonHandler());
}
private class ButtonHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if ("Reset".equals(cmd)) {
model.reset();
}
}
}
}
/**
* View
*/
class View extends JPanel {
private static final String s = "Click a button.";
private Model model;
private ColorIcon icon = new ColorIcon(80, Color.gray);
private JLabel label = new JLabel(s, icon, JLabel.CENTER);
public View(Model model) {
super(new BorderLayout());
this.model = model;
label.setVerticalTextPosition(JLabel.BOTTOM);
label.setHorizontalTextPosition(JLabel.CENTER);
this.add(label, BorderLayout.CENTER);
this.add(genButtonPanel(), BorderLayout.SOUTH);
model.addObserver(new ModelObserver());
}
private JPanel genButtonPanel() {
JPanel panel = new JPanel();
for (Piece p : Piece.values()) {
PieceButton pb = new PieceButton(p);
pb.addActionListener(new ButtonHandler());
panel.add(pb);
}
return panel;
}
private class ModelObserver implements Observer {
@Override
public void update(Observable o, Object arg) {
if (arg == null) {
label.setText(s);
icon.color = Color.gray;
} else {
if ((Boolean) arg) {
label.setText("Win!");
} else {
label.setText("Keep trying.");
}
}
}
}
private class ButtonHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
PieceButton pb = (PieceButton) e.getSource();
icon.color = pb.piece.color;
label.repaint();
model.check(pb.piece);
}
}
private static class PieceButton extends JButton {
Piece piece;
public PieceButton(Piece piece) {
this.piece = piece;
this.setIcon(new ColorIcon(16, piece.color));
}
}
private static class ColorIcon implements Icon {
private int size;
private Color color;
public ColorIcon(int size, Color color) {
this.size = size;
this.color = color;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(color);
g2d.fillOval(x, y, size, size);
}
@Override
public int getIconWidth() {
return size;
}
@Override
public int getIconHeight() {
return size;
}
}
}
/**
* Model
*/
class Model extends Observable {
private static final Random rnd = new Random();
private static final Piece[] pieces = Piece.values();
private Piece hidden = init();
private Piece init() {
return pieces[rnd.nextInt(pieces.length)];
}
public void reset() {
hidden = init();
setChanged();
notifyObservers();
}
public void check(Piece guess) {
setChanged();
notifyObservers(guess.equals(hidden));
}
}
enum Piece {
Red(Color.red), Green(Color.green), Blue(Color.blue);
public Color color;
private Piece(Color color) {
this.color = color;
}
}
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.