Using property files as UI mappings in Java:

Therefore, I am reading the selenium test design considerations document. I have questions about the UI mapping section here:

They suggested creating a properties file as follows:

admin.username = loginForm:tbUsername
admin.loginbutton = loginForm:btnLogin
admin.events.createnewevent = adminHomeForm:_activitynew
admin.events.cancel = addEditEventForm:_IDcancel
admin.events.viewoldevents = adminHomeForm:_activityold

Mapping HTML objects to keywords

Then they use it like this:

selenium.type(admin.username,"xxxxxxxx");

However, from what I've seen about attribute objects, it works very similar to hash tables Now I'm loading my properties file as follows: http://docs.oracle.com/javase/tutorial/essential/environment/properties.html Under the create and load default properties section

So use the same statement in the document I need:

selenium.type(loadedProps.get(admin.username),"xxxxxxx");

It's not bad, just not as readable as their examples, so my problem is how to load the properties file so that I can use keywords like them In addition, I am considering using page object design pattern, so if I do, I will define a pageobject base class, which will load the property file, and then extend the basic page object classes to access properties. Does that sound reasonable?

Solution

In Java, because '. " As an operator makes sense, you can't make it look like their example (not sure what they get) You can do this:

Setting code:

public class Config {
  public static String admin_username;

  static {
    Properties props = ...;
    admin_username = props.getProperty("admin.username");
  }
}

Use code:

import static Config.*;

selenium.type(admin_username,"xxxxxxxx");

If you are really crazy, you can use reflection to load the Config class (delete the template in the "static" block)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>