bdd ūüöÄ
Behat and bad HTML
<p>Some of the sites we are testing have HTML that has multiple ID that are the same. Or elements that do not really have enough info to get a class, name, label or ID out of.</p> <p>This has been a challenge and there are a few custom steps made to help get through this</p> <p> </p> <hr /> <h2>Switching to an Iframe with no name or id</h2> <p>This was hard since the default was to target the ID of the frame or name.</p> <p>Thanks to the help of this thread <a href="!topic/behat/z0z3DscjzhU" target="_blank">!topic/behat/z0z3DscjzhU</a> I was able to pull it off.</p> <p>First, using jQuery and JavaScript I enable the user to target an Iframe by finding the ID of the div that surrounds it. Second I give the frame a name / id to target.</p> <p>Then I the user can choose one of or other custom steps noted below to switch to the frame. The code still needs better error checking e.g. if the element does not exist.</p> <p><script src=""></script></p> <hr /> <h2>Finding a Submit button on the page when there are 2 with the same name and ID</h2> <p>This snippet allows the user to target a specific element on the page by adding a number. This was done a couple of months ago and at this point I think we have a better way to do it. I will show that below.</p> <p><script src=""></script></p> <hr /> <h2>Clicking Submit on a form with no button</h2> <p>There are a few ways to do this. So far this one seem to be working best.</p> <p><script src=""></script></p> <p>Of course if the form does not have an ID we would be in trouble.</p> <hr /> <h2>Switching to a popup window that has no name</h2> <p>Finally this was the toughest one. We had to use a different branch of Mink to do this. This thread was key to getting this to work <a href="!topic/behat/QNhOuGHKEWI" target="_blank">!topic/behat/QNhOuGHKEWI</a></p> <p>What we ended up with was basically from that thread</p> <p><script src=""></script></p> <hr /> <h2><span style="line-height: 1.6em;">Dealing with Alerts</span></h2> <p>Dealing with built in browser alerts was found in those threads as well.</p> <p>I then wrote a helper that I use in other methods to do this.</p> <p>Since all the steps are called from a web form they user can choose to "Click and Alert" as needed.</p> <p> </p> <p> </p> <p> </p> <p> </p> <p><script src=""></script></p> <p> </p> <h2>Comparing the Size of an element to the Window</h2> <p>Lastly (really this time) we have to check the size of an element to make sure it meets requirements.</p> <p>This custom steps allows the user to enter a class to get the height of and enter the % it should be of the window.</p> <script src=""></script> <h2>UPDATE </h2> <p>Noted in comments this might help as well</p> <p><script src=""></script></p>