automated page object generation question

瀏覽次數:251 次
跳到第一則未讀訊息

James Davis

未讀,
2013年3月26日 下午1:05:102013/3/26
收件者:seleniu...@googlegroups.com
Hello

I have been experimenting with automated page object generation and am wondering if anyone is currently using this technique? Or do folks generally hand code the page objects?

I ask because sometimes it is incredibly easy to auto-generate page objects, e.g. forms that have labels which map to the form control using the for attribute. Other times this process is incredibly complex if the html in the AUT does not follow a common coding style.

Which is more efficient?? Thanks for your response,

James Davis

Oscar Rieken

未讀,
2013年3月26日 下午1:21:572013/3/26
收件者:seleniu...@googlegroups.com
I think the problem with generating page objects is the names dont mean anything. I prefer to hand code them and make the name of the object mean something. also i try and teach my team to not use what the object is in the name this makes thing harder to read


<a id="as-1232" href="http://www.blah.com/home">Home</a>
would you generate "as_1231_link" as a name for this element

to me this would be "home"
@some_site.some_page.home.click

<li>
  <label for="first_name">First Name</label>
  <input id="first_name" name="first_name" placeholder="First Name" required="" type="text">
</li>

would you generate "first_name_text_box"

to me this would just be first_name
@some_site.some_page.first_name.set "Oscar"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/FjGT1jiSfP4J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Simon Stewart

未讀,
2013年3月26日 下午1:48:502013/3/26
收件者:seleniu...@googlegroups.com
The idea behind the Page Object pattern is that they model the _services_ offered by the page. That is, although a page might have a form with two fields --- "email" and "passwd" --- the service it offers the ability to log in to the site. The expected API for this Page Object would be something like:

public class LoginPage {

  ...

  public HomePage loginAs(Credentials user) {
    driver.findElement(By.name("email")).sendKeys(user.getEmail());
    driver.findElement(By.name("passwd)).sendKeys(user.getPassword());
    // somehow submit the form and wait for the home page to load
    return new HomePage(driver);
  }

  ...
}

This isn't really something that can be autogenerated. To minimize the pain of writing page objects, and to remove some of the boilerplate, I introduced the PageFactory class, which reads annotations on fields in a class to help find elements easily.

Regards,

Simon

David Lai

未讀,
2013年3月26日 下午4:47:172013/3/26
收件者:seleniu...@googlegroups.com
The WTF framework I'm working on has a chrome plugin that'll help you generate the page validation and object mappings for a page object.  


But like others have mentioned, it's up to you to take it the rest of the way to identifying the Atomic level transactions that your page can perform.

Nick

未讀,
2013年3月26日 晚上8:34:302013/3/26
收件者:seleniu...@googlegroups.com
On Wednesday, March 27, 2013 4:48:50 AM UTC+11, Simon Stewart wrote:
The idea behind the Page Object pattern is that they model the _services_ offered by the page.

That's a topic for endless discussion :) I know that many people use Page-Object to describe what Simon defined here. But I can't agree with that.

I think Page-Object as a pattern should be only about wrapping of web pages layout and its components into Java classes with _interface_ logic defined in those classes. Driving of application _services_ logic should be coded separately (following best practices of OOD).

I've recently started calling approach described by me differently. I use (Page-)Component-Object term... unfortunately I still don't have enough time to share it in the Internet.

 

Tim Bergmann

未讀,
2013年7月23日 清晨5:40:142013/7/23
收件者:seleniu...@googlegroups.com
There is actually a new tool in development I came across recently when I looked for solutions on this issue. It's called OHMAP. It currently provides a web interface that let's you input your page source code and then automatically maps input fields and/or other elements you want to get mapped (you can use xpath expressions). It also let's you specify a number of parameters of the resulting page object.

link to the tool: http://ohmap.virtuetech.de/

for a list current features: http://www.virtuetech.de/ohmap/

I've read that they plan to release a firefox plugin at a later development stage. That would be cool.

Tim

Oscar Rieken

未讀,
2013年7月23日 晚上10:05:392013/7/23
收件者:seleniu...@googlegroups.com
the problem with page object generation tools is mainly that the names it generates tend to have no meaning
For example.
This Element:
<input id='inp_fn_23' name='inp_fn_23' placeholder='First Name' required type='text'>
Becomes this:
package your.package.name.goes.here;

import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class YourPageObjectName {

	@FindBy(id = "inp_fn_23")
	public WebElement inpFn23;

}

"inpFn23" has no meaning, If i were creating this by hand it would probably be called "firstName" because thats what the field is. If you have to go back and rename everything to where it makes sense, why not just do it in the first place. Also, Why would you need to define every object on a page at once. I think you define page objects for things you actually need in a test, having elements defined but never used just leads to a lot of code in your framework that never gets touched. 

just my opinion


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Tim Bergmann

未讀,
2013年7月24日 清晨6:47:012013/7/24
收件者:seleniu...@googlegroups.com
I bumped into the same issue and wrote the developers a mail adressing the problem. They responded that they'll implement more intelligent ways to identify names and that the user can decide where the names come from if he chooses to. 

I made different experiences regarding the second thing you mentioned. I prefer to have all inputfields included in my page object (if possible). There are I think two good reasons for that. First, you want a good test coverage, so you need to make use of a good share of your input fields. Second, if you create page objects for your user interface which include all the input fields today, you can easily implement another testcase tommorow, because everything is already mapped. There is no need to navigate through the application again to search for a particular element.

Chamila

未讀,
2015年4月17日 凌晨3:54:282015/4/17
收件者:seleniu...@googlegroups.com
I created project to automated page object generation.

Please check it on git hub

https://github.com/chamiz/SeleniumPageObjectGenerator.git.

If you want modifications please inform me.



--
View this message in context: http://selenium.10932.n7.nabble.com/automated-page-object-generation-question-tp22484p44108.html
Sent from the Selenium - Users mailing list archive at Nabble.com.
回覆所有人
回覆作者
轉寄
0 則新訊息