After a good night's sleep, I've come up with the following solution. It
works, which I guess is the key point, but it doesn't feel very nice.
public void setUp() throws Exception {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import ro.config_file");
interpreter.exec("cf = ro.config_file.config_file()");
// connect to the selenium proxy
interpreter.exec("env = cf.environment");
interpreter.exec("url = '%s://%s:%s' % (env['protocol'], env['host'],
env['port'])");
PyObject pyUrl = interpreter.get("url");
String url = (String)pyUrl.__tojava__(String.class);
browser = new DefaultSelenium("localhost", 4444, "*chrome", url);
browser.start();
// get our user info
interpreter.exec("user = cf.users['setupuser']['username']");
PyObject pyUser = interpreter.get("user");
String username = (String)pyUser.__tojava__(String.class);
interpreter.exec("password = cf.users['setupuser']['password']");
PyObject pyPassword = interpreter.get("password");
String password = (String)pyPassword.__tojava__(String.class);
// login
browser.open("<my page>");
browser.selectFrame("<my frame>");
browser.type("Login.Token1", username);
browser.type("Login.Token2", password);
browser.click("realLogon");
}
-adam
> Sorry for both the bad subject, and what will likely be a simple thing to
> do
> but I've had the flu for 4 days and am not quite thinking straight yet.
>
> I have a java class (in this case, it is junit based) which I want to be
> able to populate some values based on information stored in a python
> object.
> *In theory* I have created the object, but I cannot figure out how to
> extract the actual information. This class is being loaded inside jython
> using __import__.
>
> When I try to run my script I get the following, which is stumping me.
> C:\work\jonah\internal\jams\products\ro\tests\tmp\ro_tmp_ipfilter.java:15:
> cannot find symbol
> symbol : method configure()
> location: class org.python.core.PyObject
> configObj.configure();
> ^
> 1 error
> could not import ro_tmp_ipfilter.java
>
> When I print configObj it looks like it has done what I think it should
> have
> <ro.config_file.config_file object 3>
>
> Here is a whole bunch of code to hopefully illustrate what I am trying to
> do.
> <junit class>
> import org.python.util.PythonInterpreter;
> import org.python.core.*;
> import junit.framework.*;
> import com.thoughtworks.selenium.*;
>
> public class ro_tmp_ipfilter extends TestCase {
> private Selenium browser;
>
> public void setUp() throws Exception {
> PythonInterpreter interpreter = new PythonInterpreter();
> interpreter.exec("from ro.config_file import config_file");
> PyObject jyConfigFileClass = interpreter.get("config_file");
> PyObject configObj = jyConfigFileClass.__call__();
> configObj.configure();
>
> // this value for instance would be super handy to set from things
> stored in configObj.environment
> String url = "http://www.google.com";
> browser = new DefaultSelenium("localhost", 4444, "*firefox", url);
> browser.start();
> }
>
> protected void tearDown() throws Exception {
> browser.stop();
> }
>
> //other test methods
>
> }
> </junit class>
>
> <the ro.config_file class>
> class config_file(framework.base_config_file.base_config_file):
> def configure(self):
> self.environment = {}
> environment_nodes =
> self.config_dom.getElementsByTagName("environment")[0]
> for n in environment_nodes.childNodes:
> if n.nodeType == xml.dom.Node.ELEMENT_NODE:
> self.environment[n.tagName] = n.firstChild.data
>
> #users
> self.users = {}
> user_nodes = self.config_dom.getElementsByTagName("user")
> for user_node in user_nodes:
> for el in user_node.childNodes:
> if el.nodeType == xml.dom.Node.ELEMENT_NODE:
> if user_node.getAttribute("id") not in self.users:
> self.users[user_node.getAttribute("id")] = {}
> self.users[user_node.getAttribute("id")][el.tagName] =
> el.firstChild.data
>
> # database
> self.db = {}
> db_nodes = self.config_dom.getElementsByTagName("database")[0]
> for n in db_nodes.childNodes:
> if n.nodeType == xml.dom.Node.ELEMENT_NODE:
> self.db[n.tagName] = n.firstChild.data
> </the ro.config_file class>
> All framework.base_config_file.base_config_file does is parse an xml file
> and set it's dom to self.config_dom so is out of context of this
> particular
> problem I think.
>
> Thanks.
>
> -adam (whose 4yr old entered round 2 of the flu during the course of
> writing
> this email. oh, fun.)
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|