Great points Mark, thanks. That will be a good reasoning of disadvantages to the approach.
Also wanted to point out though that going properties file approach, one doesn't have to lump all locators in a single properties file. You could split it up architecturally as you see fit. Same as whether you lump all Selenium code in a single class file or
break it up w/ OOP and/or page objects.
And on topic of page objects, at least from my collaborations, you can group locators for page together with the page methods/actions or split them up into separate files (there's no set in stone standard like with agile). And if you chose to keep them separate
in the page object design, you can then also implement with properties files with one property file mapped to each page object.
On Sunday, September 30, 2012 1:18:27 AM UTC-7, Mark Collin wrote:
I think a long list of locators hidden away in a property file is insane, you end up with long unreadable lists of rubbish. It may well look manageable at first but eventually it gets really long and anybody new looking at the codebase has to sit there
for hours trying to work out where everything links together. Secondly if you have a long list of locators hidden away in a properties file and you want to change the name of one of these properties you have refactoring hell (If you are using a decent modern
IDE like IntelliJ IDEA you can change the name of a variable in one place and it will change that name everywhere else for you). Keep it in the code is my recommendation.
What you should really do is use page objects. Page objects can be for a whole page, or you could split out a consistent bit of functionality into its own page object (for example if you have a header and menu bar that is consistent across the whole site
split it out into its own page object and reuse it in your other page objects).
At the end of the day there are many ways you can structure your data, but try and do something that makes it maintainable in the future and easy for new people who join the project to understand.
From:seleniu...@xxxxxxxxxxxxxxxx[mailto:seleniu...@xxxxxxxxxxxxxxxx]On
Behalf OfDavid
Sent:29 September 2012 07:45
To:seleniu...@xxxxxxxxxxxxxxxx
Subject:[selenium-users] Re: How to use values of properties file in selenium code
I think there is debate on the topic of whether it is good or bad, though the general consensus is to stay away from it. Personally, I think it really depends on how you structure & manage your test data & code which determines whether this will be useful
to you or not.
I personally would advocate it. I consider locators as a form of test data (though not of the same type as input data used to say type into text fields, etc.). If you look at it that way, then it is better to abstract it out of the test code and treated
as a "config" or properties and used similarly to data driven testing of being fetched from external source. Is also useful for changing locators w/o having to recompile the Java test code. But doing it this way, you loose integration of locators being matched
up with the test code/flow, in case that is needed, particularly say if combined with page objects.
And if you do use property files for locators, it becomes more useful if you abstract out the locatory type from code, so instead of
driver.findElement(By.cssSelector(OR.getProperty("loginButton"))).click();
you have something like this
driver.findElement(myUtilityClass.parseLocator(OR.getProperty("loginButton"))).click();
wheremyUtilityClass.parseLocator() is a custom class method you write that will figure out the locator type from what you pass into it and return appropriate By object. The figure out coudl be like matching against locator prefix for Selenium RC style locators,
in which case your property file would contain something like this
loginButton=css=someCssSelectorValue
emailAddress=xpath=someXpathValue
password=id=someIdValue
though of course I haven't done this myself, but that's how you would do it in theory, so callingOR.getProperty("loginButton") would return "css=someCssSelectorValue"
this approach also helps if you're migrating over from Selenium RC, so can keep RC locators intact, if they still work in WebDriver w/o modification of the values.
On Thursday, September 27, 2012 9:22:31 PM UTC-7, akki wrote:
Hey Syed, I was also considering the same approach to store my locators. Would you please elaborate on why it is not a good approach and which is a better approach.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email toseleniu...@xxxxxxxxxxxxxxxx.
To unsubscribe from this group, send email toselenium-user...@xxxxxxxxxxxxxxxx.
To view this discussion on the web visithttps://groups.google.com/d/msg/selenium-users/-/VZdgWKWVaWIJ.
For more options, visithttps://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@xxxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to selenium-users+unsubscribe@xxxxxxxxxxxxxxxxx
To view this discussion on the web visit
https://groups.google.com/d/msg/selenium-users/-/9rWYDoHw9DkJ.
For more options, visithttps://groups.google.com/groups/opt_out.
http://osdir.com/ml/selenium-users/2012-09/msg02103.html
分享到:
相关推荐
10. Open a text editor and wirte your selenium test script code and save the file as googlesearch.rb under your test script folder in this example c:\seleniumrubytest 11. Go to c:\seleniumrubytest ...
selenium-server-standalone-2.40.0.jar 、selenium-java-2.40.0-srcs.jar 、selenium-java-2.40.0.jar
selenium-java-2.44.0.jar selenium-java-2.44.0-srcs.jar selenium-server-standalone-2.44.0.jar
java+selenium实现web自动化测试需要用到的jar包。不过某些情况下Selenium-server-standalone包即可,Selenium-java没有使用也可以运行
Selenium 服务器(selenium-server-4.1.1.jar)
selenium-java-2.45.0.jar
selenium-server-standalone-4.0.0-alpha-2.zip
最新版selenium-java,selenium-server-standalone-3.141.0.jar
selenium-java-3.141.59.jar selenium java自动化
selenium-java-2.41.0,selenium-java-2.33 完整包下载
selenium-server-standalone-3.141.59.jar
selenium-server-standalone-2.44.0, selenium最新服务器,
selenium-java-2.47.1.zip,2015年8月更新
selenium3.9.0-server-standalone.jar文件,需要的赶紧下载了
selenium-server-standalone-2.44.0,selenium-java-2.44.0,java-client-2.2.0三件套
selenium-java-3.141.59.zip
selenium-api-4.0.0- alpha- 6.jar 文件下载
selenium-server-standalone-3.141.59.jar selenium-server-standalone-3.141.59.jar
selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包 selenium-htmlunit-driver-2.9.0jar包