Some test automation require you to look at the page source to confirm tags. This article covers opening the view source to assert tags are present using Ruby. Here’s a quick way to validate text on page source using ruby.
Tags and View Source
There are a number of tags that could be used for testing and are only viewable on the source page. Often times, we leave this to manual testing to verify once or twice. Most of the tags that I have tested were used for SEO. The script below is a great way to switch between the standard webpage view and the view source page using Chrome and Selenium.
source = $driver.current_url $driver.get('view-source:' + source) body_element = $driver.find_element(:tag_name => "body") if body_element assert(body_element.text.include?(['text to validate'])) end $driver.get(source)
You might like these as well:
- Code Snippet: Using a config file for Ruby Automation
- Snippet: Using a config file for CasperJS and PhantomJS