I have a problem in below code, this frmChinese.append(txtField); is not working for me.
What is the correct way to bind this text field with my form? The header files and libraries that I have used have also been mentioned.
package com.lbs;
import com.lbs.MidletSplashScreen;
import com.sun.lwuit.*;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
public class Chinese extends Form implements ActionListener {
Form frmChinese = null;
Command cmdExit = null;
TextField txtField = null;
Chinese() {
frmChinese = this;
frmChinese.setTitle("Chinese");
frmChinese.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
this.getStyle().setBgColor(0xFF5240);
ShowUi();
cmdExit = new Command("Exit");
Command cmdBack = new Command("Back"); // new command with name Back
frmChinese.addCommand(cmdExit);// add command in Form
frmChinese.addCommand(cmdBack);// add command in Form
frmChinese.setBackCommand(cmdBack); // setting back command
frmChinese.addCommandListener(this); // register action listener in form
}
private void ShowUi() {
txtField = new TextField("","Search", 20, TextField.ANY);
frmChinese.append(txtField);
}
What you need to use is te addComponent method from the Form Class. In lwuit the basic interface elements are Components. Adding this Components to your Form's Layout, you can built some cool designs.
Take a look here:
LWUIT Layouts
Related
I am new to selenium cucumber. I am getting an error on the feature file "no definitions found ..". But I have written the definitions. I also can execute the cucumber tests just fine.
Feature:
Feature: LOGIN_FEATURE
Scenario: login scenario
Given User is already on login page
When title is crom
Then user enters un and pw
Step definition:
package stepDefinition;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.junit.Assert.*;
//import org.junit.Assert;
import static org.testng.Assert.assertTrue;
//import cucumber.api.java.en.Given;
public class loginStepDef {
WebDriver driver;
//#Then"^login should be unsuccessful$"
#Given ("^User is already on login page$")
public void User_already_on_login_page(){
System.out.println("givenM method started");
System.setProperty("webdriver.chrome.driver","C:\\src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://web.bettylist.com/user");
System.out.println("---Navigated to the URL.");
}
//#SuppressWarnings("deprecation")
#When("^title is crom$")
public void title_is_crom(){
System.out.println("whenM started.");
String title = driver.getTitle();
System.out.println("title" + title);
//Assert.assertEquals("Ff", title);
assertEquals("Log in | bettylist", title);
System.out.println("---validated the title before logging in.");
}
Runner:
package MyRunner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
//import cucumber.junit.Cucumber;
//import cucumber.api.CucumberOptions;
//import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "workspace/Cucumber3/src/main/java/Features",
glue="stepDefinition"
//format = {"pretty", "html:target/Destination"}
//plugin = {"pretty","html:test-outout"},
//plugin = {"json:Folder_Name1/cucumber.json"},
//plugin = {"junit:Folder_Name/cucumber.xml"},
//dryRun = false
//monochrome = false,
//strict = false
)
public class TestRunner {
}
I am using ecliipse IDE. I also installed Natural plugin. How can I fix the no definitions found in the feature file?
mockito-1.10.19
powermock-mockito-1.7.1
powermock-1.7.4
junit 4.12
I have a class that has multiple constructors (java). Once constructor calls the other. I want to mock only 1 of the constructors (the one that is called from the other). I cannot change the code unfortunately - I am just testing it. Here is the class to be tested:
import java.io.File;
import java.sql.connection;
public class Foo {
public Foo (Connection connection){
this(connection, new File ());
}
public Foo (Connection connection, File file){
// do stuff
}
// other methods
}
Here is the test class I have written:
import java.io.File;
import java.sql.connection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.legacy.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(Foo.class)
#PowerMockIgnore("javax.management.*")
public class FooTest {
#Test
public void testFoo() throws Exception {
Connection mockConnection = Mockito.mock(Connection.class);
Foo fooObj = Mockito.mock(Foo.class);
PowerMockito.whenNew(Foo.class).withArguments(Matchers.notNull(), Matchers.notNull()).thenReturn(fooObj);
Foo newFooObj = new Foo (mockConnection);
assertNotNull ("newFooObj should not be null", newFooObj);
}
}
The problem is that Foo(Connection) is not being entered. Is there something I am missing?
I tried your code with the latest 1.7.x version of Powermock (1.7.4) and it works as you wanted it to. So you might just need to upgrade a few minor versions.
I would like to get the number of tests running with a specific browser in the selenium grid.
I have looked at the existing API, where i can get the slotcount which is the sum of all the available slots which includes all the browsers.
ex: curl -X GET http://localhost:4444/grid/api/hub/ -d '{"configuration":["slotCounts"]}'
Output will be: {"success":true,"slotCounts":{"free":178,"total":196}}
Is there any API available to get how many slots of chrome browser(say) available?
Other options come to my mind is to parse the existing API
curl -X GET http://localhost:4444/grid/console
which return the full stack, where i need to parse the html structure, which is like
<img src='/grid/resources/org/openqa/grid/images/chrome.png' width='16' height='16' class='busy' title='POST - /session/8802ebae-10cb-480d-bbbd-5e7edd7ee7b2/execute executed.' />
No. Currently there's no such API available out there in the Selenium Grid that can do this for you.
You would need to build a custom servlet which when invoked can extract and provide this information for you.
Your Hub servlet could look like this:
import org.openqa.grid.internal.ProxySet;
import org.openqa.grid.internal.Registry;
import org.openqa.grid.internal.RemoteProxy;
import org.openqa.grid.web.servlet.RegistryBasedServlet;
import org.openqa.selenium.remote.CapabilityType;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class SimpleServlet extends RegistryBasedServlet {
public SimpleServlet(Registry registry) {
super(registry);
}
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
ProxySet proxySet = getRegistry().getAllProxies();
Iterator<RemoteProxy> iterator = proxySet.iterator();
Map<String, List<String>> returnValue = new HashMap<>();
while (iterator.hasNext()) {
RemoteProxy each = iterator.next();
each.getTestSlots().forEach(slot -> {
String browser = (String) slot.getCapabilities().get(CapabilityType.BROWSER_NAME);
String machineIp = each.getRemoteHost().getHost();
List<String> machines = returnValue.get(browser);
if (machines == null) {
machines = new ArrayList<>();
}
machines.add(machineIp);
returnValue.put(browser, machines);
});
}
//Write logic to have the Map returned back as perhaps a JSON payload
}
}
You can refer to the Selenium documentation here to learn how to inject servlets to the Hub or the node.
This is a simple program that's supposed to change the background color of a pane from a list of colors. However,
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JRadioButton;
import javax.swing.event.ListSelectionListener;
public class JL1st extends JFrame{
private JList list;
private static String[] colornames = {"black","blue","red","white"};
private static Color[] colors = {Color.BLACK, Color.BLUE, Color.RED, Color.WHITE};
public JL1st(){
super("title");
setLayout(new FlowLayout());
list = new JList(colornames);
list.setVisibleRowCount(4);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
add(new JScrollPane(list));
list.ListSelectionListener(
new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event){
getContentPane().setBackground(colors[list.getSeletedIndex]);
}
}
);
}
}
I keep getting an error on "ListSelectionListener" The method ListSelectionListener(new ListSelectionListener(){}) is undefined for the type JList
Could it be that I have a missing import or is it just messed up syntax?
Thanks
Problem solved,
ListSelectionListener wasn't imported.
I'm using Richfaces 3, Facelets (a pre-JSF 2 version), and Tomcat. I am working on adding a Richfaces Tree to my page, but get this error:
org.richfaces.model.TreeNodeImpl cannot be cast to javax.swing.tree.TreeNode
Here is the code I'm using to build the list of nodes:
int i = 0;
TreeNodeImpl<String> rootNode = new TreeNodeImpl<String>();
for( Recommendation recommendation : m_recommendationsBean.getRecommendations() )
{
final TreeNodeImpl<String> childNode = new TreeNodeImpl<String>();
childNode.setData( recommendation.getEventDescription() );
rootNode.addChild( i, childNode );
i++;
}
m_treeNodes.add( rootNode );
And then:
#NotNull
public List<TreeNodeImpl<String>> getTreeNodes ()
{
return m_treeNodes;
}
And my page just has this:
<rich:tree value="#{DmsRecommendationsPage.treeNodes}" var="recommendation">
<rich:treeNode>
#{recommendation}
</rich:treeNode>
</rich:tree>
Any ideas? Thanks!
Check your imports. RichFaces' own org.richfaces.model.TreeNode interface should be used in the property declaration. You've likely picked the first option of the IDE autosuggestion to import the Swing one instead of the RichFaces one while declaring the TreeNode.
Replace
import javax.swing.tree.TreeNode;
by
import org.richfaces.model.TreeNode;
For other readers:
The javax.swing.tree.TreeNode is used in the Richfaces showcase here:
http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=tree&skin=blueSky
It seems both are possible. The documentation states:
The data model must be either an org.richfaces.model.TreeNode
interface, an org.richfaces.model.TreeDataModel interface, or a
javax.swing.tree.TreeNode interface.
package org.richfaces.demo.tree.model;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.google.common.collect.Iterators;
public class Country extends NamedNode implements TreeNode {