How to use started_on method in autotest

Best Python code snippet using autotest_python

test_toastertable_ui.py

Source:test_toastertable_ui.py Github

copy

Full Screen

1#! /usr/bin/env python2# ex:ts=4:sw=4:sts=4:et3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-4#5# BitBake Toaster Implementation6#7# Copyright (C) 2013-2016 Intel Corporation8#9# This program is free software; you can redistribute it and/or modify10# it under the terms of the GNU General Public License version 2 as11# published by the Free Software Foundation.12#13# This program is distributed in the hope that it will be useful,14# but WITHOUT ANY WARRANTY; without even the implied warranty of15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16# GNU General Public License for more details.17#18# You should have received a copy of the GNU General Public License along19# with this program; if not, write to the Free Software Foundation, Inc.,20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.21from datetime import datetime22from django.core.urlresolvers import reverse23from django.utils import timezone24from tests.browser.selenium_helpers import SeleniumTestCase25from orm.models import BitbakeVersion, Release, Project, Build26class TestToasterTableUI(SeleniumTestCase):27 """28 Tests for the UI elements of ToasterTable (sorting etc.);29 note that the tests cover generic functionality of ToasterTable which30 manifests as UI elements in the browser, and can only be tested via31 Selenium.32 """33 def setUp(self):34 pass35 def _get_orderby_heading(self, table):36 """37 Get the current order by finding the column heading in <table> with38 the sorted class on it.39 table: WebElement for a ToasterTable40 """41 selector = 'thead a.sorted'42 heading = table.find_element_by_css_selector(selector)43 return heading.get_attribute('innerHTML').strip()44 def _get_datetime_from_cell(self, row, selector):45 """46 Return the value in the cell selected by <selector> on <row> as a47 datetime.48 row: <tr> WebElement for a row in the ToasterTable49 selector: CSS selector to use to find the cell containing the date time50 string51 """52 cell = row.find_element_by_css_selector(selector)53 cell_text = cell.get_attribute('innerHTML').strip()54 return datetime.strptime(cell_text, '%d/%m/%y %H:%M')55 def test_revert_orderby(self):56 """57 Test that sort order for a table reverts to the default sort order58 if the current sort column is hidden.59 """60 now = timezone.now()61 later = now + timezone.timedelta(hours=1)62 even_later = later + timezone.timedelta(hours=1)63 bbv = BitbakeVersion.objects.create(name='test bbv', giturl='/tmp/',64 branch='master', dirpath='')65 release = Release.objects.create(name='test release',66 branch_name='master',67 bitbake_version=bbv)68 project = Project.objects.create_project('project', release)69 # set up two builds which will order differently when sorted by70 # started_on or completed_on71 # started first, finished last72 build1 = Build.objects.create(project=project,73 started_on=now,74 completed_on=even_later,75 outcome=Build.SUCCEEDED)76 # started second, finished first77 build2 = Build.objects.create(project=project,78 started_on=later,79 completed_on=later,80 outcome=Build.SUCCEEDED)81 url = reverse('all-builds')82 self.get(url)83 table = self.wait_until_visible('#allbuildstable')84 # check ordering (default is by -completed_on); so build1 should be85 # first as it finished last86 active_heading = self._get_orderby_heading(table)87 self.assertEqual(active_heading, 'Completed on',88 'table should be sorted by "Completed on" by default')89 row_selector = '#allbuildstable tbody tr'90 cell_selector = 'td.completed_on'91 rows = self.find_all(row_selector)92 row1_completed_on = self._get_datetime_from_cell(rows[0], cell_selector)93 row2_completed_on = self._get_datetime_from_cell(rows[1], cell_selector)94 self.assertTrue(row1_completed_on > row2_completed_on,95 'table should be sorted by -completed_on')96 # turn on started_on column97 self.click('#edit-columns-button')98 self.click('#checkbox-started_on')99 # sort by started_on column100 links = table.find_elements_by_css_selector('th.started_on a')101 for link in links:102 if link.get_attribute('innerHTML').strip() == 'Started on':103 link.click()104 break105 # wait for table data to reload in response to new sort106 self.wait_until_visible('#allbuildstable')107 # check ordering; build1 should be first108 active_heading = self._get_orderby_heading(table)109 self.assertEqual(active_heading, 'Started on',110 'table should be sorted by "Started on"')111 cell_selector = 'td.started_on'112 rows = self.find_all(row_selector)113 row1_started_on = self._get_datetime_from_cell(rows[0], cell_selector)114 row2_started_on = self._get_datetime_from_cell(rows[1], cell_selector)115 self.assertTrue(row1_started_on < row2_started_on,116 'table should be sorted by started_on')117 # turn off started_on column118 self.click('#edit-columns-button')119 self.click('#checkbox-started_on')120 # wait for table data to reload in response to new sort121 self.wait_until_visible('#allbuildstable')122 # check ordering (should revert to completed_on); build2 should be first123 active_heading = self._get_orderby_heading(table)124 self.assertEqual(active_heading, 'Completed on',125 'table should be sorted by "Completed on" after hiding sort column')126 cell_selector = 'td.completed_on'127 rows = self.find_all(row_selector)128 row1_completed_on = self._get_datetime_from_cell(rows[0], cell_selector)129 row2_completed_on = self._get_datetime_from_cell(rows[1], cell_selector)130 self.assertTrue(row1_completed_on > row2_completed_on,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful