1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-02 01:19:52 +00:00

bitbake: toaster: update selenium version and code syntax

Updated selenium version to latest 4.13.0, changed selenum specific version syntax elements to accomplish test success

(Bitbake rev: 868c88a249ef4b9fe5a891e76e25e054e4fcd994)

Signed-off-by: Marlon Rodriguez Garcia <marlon.rodriguez-garcia@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Marlon Rodriguez Garcia
2023-10-03 13:26:23 -04:00
committed by Richard Purdie
parent 08421d8985
commit 3ac4694fc3
16 changed files with 156 additions and 118 deletions
@@ -21,6 +21,7 @@ import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException, \
StaleElementReferenceException, TimeoutException
@@ -32,9 +33,7 @@ def create_selenium_driver(cls,browser='chrome'):
browser = env_browser
if browser == 'chrome':
return webdriver.Chrome(
service_args=["--verbose", "--log-path=selenium.log"]
)
return webdriver.Chrome()
elif browser == 'firefox':
return webdriver.Firefox()
elif browser == 'marionette':
@@ -153,11 +152,11 @@ class SeleniumTestCaseBase(unittest.TestCase):
def find(self, selector):
""" Find single element by CSS selector """
return self.driver.find_element_by_css_selector(selector)
return self.driver.find_element(By.CSS_SELECTOR, selector)
def find_all(self, selector):
""" Find all elements matching CSS selector """
return self.driver.find_elements_by_css_selector(selector)
return self.driver.find_elements(By.CSS_SELECTOR, selector)
def element_exists(self, selector):
"""
@@ -7,7 +7,7 @@
# SPDX-License-Identifier: GPL-2.0-only
#
import re
import re, time
from django.urls import reverse
from django.utils import timezone
@@ -15,6 +15,8 @@ from tests.browser.selenium_helpers import SeleniumTestCase
from orm.models import BitbakeVersion, Release, Project, Build, Target
from selenium.webdriver.common.by import By
class TestAllBuildsPage(SeleniumTestCase):
""" Tests for all builds page /builds/ """
@@ -91,7 +93,7 @@ class TestAllBuildsPage(SeleniumTestCase):
found_row = None
for row in rows:
outcome_links = row.find_elements_by_css_selector(selector)
outcome_links = row.find_elements(By.CSS_SELECTOR, selector)
if len(outcome_links) == 1:
found_row = row
break
@@ -131,17 +133,19 @@ class TestAllBuildsPage(SeleniumTestCase):
url = reverse('all-builds')
self.get(url)
# should see a rebuild button for non-command-line builds
selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % build1.id
time.sleep(2)
run_again_button = self.find_all(selector)
self.assertEqual(len(run_again_button), 1,
'should see a rebuild button for non-cli builds')
# shouldn't see a rebuild button for command-line builds
selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % default_build.id
run_again_button = self.find_all(selector)
self.assertEqual(len(run_again_button), 0,
'should not see a rebuild button for cli builds')
# should see a rebuild button for non-command-line builds
selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % build1.id
run_again_button = self.find_all(selector)
self.assertEqual(len(run_again_button), 1,
'should see a rebuild button for non-cli builds')
def test_tooltips_on_project_name(self):
"""
@@ -198,24 +202,24 @@ class TestAllBuildsPage(SeleniumTestCase):
# test recent builds area for successful build
element = self._get_build_time_element(build1)
links = element.find_elements_by_css_selector('a')
links = element.find_elements(By.CSS_SELECTOR, 'a')
msg = 'should be a link on the build time for a successful recent build'
self.assertEquals(len(links), 1, msg)
# test recent builds area for failed build
element = self._get_build_time_element(build2)
links = element.find_elements_by_css_selector('a')
links = element.find_elements(By.CSS_SELECTOR, 'a')
msg = 'should not be a link on the build time for a failed recent build'
self.assertEquals(len(links), 0, msg)
# test the time column for successful build
build1_row = self._get_row_for_build(build1)
links = build1_row.find_elements_by_css_selector('td.time a')
links = build1_row.find_elements(By.CSS_SELECTOR, 'td.time a')
msg = 'should be a link on the build time for a successful build'
self.assertEquals(len(links), 1, msg)
# test the time column for failed build
build2_row = self._get_row_for_build(build2)
links = build2_row.find_elements_by_css_selector('td.time a')
links = build2_row.find_elements(By.CSS_SELECTOR, 'td.time a')
msg = 'should not be a link on the build time for a failed build'
self.assertEquals(len(links), 0, msg)
@@ -16,6 +16,8 @@ from tests.browser.selenium_helpers import SeleniumTestCase
from orm.models import BitbakeVersion, Release, Project, Build
from orm.models import ProjectVariable
from selenium.webdriver.common.by import By
class TestAllProjectsPage(SeleniumTestCase):
""" Browser tests for projects page /projects/ """
@@ -117,7 +119,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the release text for the default project
selector = 'span[data-project-field="release"] span.text-muted'
element = default_project_row.find_element_by_css_selector(selector)
element = default_project_row.find_element(By.CSS_SELECTOR, selector)
text = element.text.strip()
self.assertEqual(text, 'Not applicable',
'release should be "not applicable" for default project')
@@ -127,7 +129,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the link in the release cell for the other project
selector = 'span[data-project-field="release"]'
element = other_project_row.find_element_by_css_selector(selector)
element = other_project_row.find_element(By.CSS_SELECTOR, selector)
text = element.text.strip()
self.assertEqual(text, self.release.name,
'release name should be shown for non-default project')
@@ -152,7 +154,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the machine cell for the default project
selector = 'span[data-project-field="machine"] span.text-muted'
element = default_project_row.find_element_by_css_selector(selector)
element = default_project_row.find_element(By.CSS_SELECTOR, selector)
text = element.text.strip()
self.assertEqual(text, 'Not applicable',
'machine should be not applicable for default project')
@@ -162,7 +164,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the link in the machine cell for the other project
selector = 'span[data-project-field="machine"]'
element = other_project_row.find_element_by_css_selector(selector)
element = other_project_row.find_element(By.CSS_SELECTOR, selector)
text = element.text.strip()
self.assertEqual(text, self.MACHINE_NAME,
'machine name should be shown for non-default project')
@@ -187,7 +189,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the link on the name field
selector = 'span[data-project-field="name"] a'
element = default_project_row.find_element_by_css_selector(selector)
element = default_project_row.find_element(By.CSS_SELECTOR, selector)
link_url = element.get_attribute('href').strip()
expected_url = reverse('projectbuilds', args=(self.default_project.id,))
msg = 'link on default project name should point to builds but was %s' % link_url
@@ -198,7 +200,7 @@ class TestAllProjectsPage(SeleniumTestCase):
# check the link for the other project
selector = 'span[data-project-field="name"] a'
element = other_project_row.find_element_by_css_selector(selector)
element = other_project_row.find_element(By.CSS_SELECTOR, selector)
link_url = element.get_attribute('href').strip()
expected_url = reverse('project', args=(self.project.id,))
msg = 'link on project name should point to configuration but was %s' % link_url
@@ -15,6 +15,8 @@ from tests.browser.selenium_helpers import SeleniumTestCase
from orm.models import Project, Release, BitbakeVersion, Build, LogMessage
from orm.models import Layer, Layer_Version, Recipe, CustomImageRecipe, Variable
from selenium.webdriver.common.by import By
class TestBuildDashboardPage(SeleniumTestCase):
""" Tests for the build dashboard /build/X """
@@ -183,7 +185,7 @@ class TestBuildDashboardPage(SeleniumTestCase):
found = False
for element in message_elements:
log_message_text = element.find_element_by_tag_name('pre').text.strip()
log_message_text = element.find_element(By.TAG_NAME, 'pre').text.strip()
text_matches = (log_message_text == expected_text)
log_message_pk = element.get_attribute('data-log-message-id')
@@ -213,7 +215,7 @@ class TestBuildDashboardPage(SeleniumTestCase):
the WebElement modal match the list of text values in expected
"""
# labels containing the radio buttons we're testing for
labels = modal.find_elements_by_css_selector(".radio")
labels = modal.find_elements(By.CSS_SELECTOR,".radio")
labels_text = [lab.text for lab in labels]
self.assertEqual(len(labels_text), len(expected))
@@ -248,7 +250,7 @@ class TestBuildDashboardPage(SeleniumTestCase):
selector = '[data-role="edit-custom-image-trigger"]'
self.click(selector)
modal = self.driver.find_element_by_id('edit-custom-image-modal')
modal = self.driver.find_element(By.ID, 'edit-custom-image-modal')
self.wait_until_visible("#edit-custom-image-modal")
# recipes we expect to see in the edit custom image modal
@@ -270,7 +272,7 @@ class TestBuildDashboardPage(SeleniumTestCase):
selector = '[data-role="new-custom-image-trigger"]'
self.click(selector)
modal = self.driver.find_element_by_id('new-custom-image-modal')
modal = self.driver.find_element(By.ID,'new-custom-image-modal')
self.wait_until_visible("#new-custom-image-modal")
# recipes we expect to see in the new custom image modal
@@ -6,7 +6,7 @@
#
# Copyright (C) 2013-2016 Intel Corporation
#
import time
from django.urls import reverse
from django.utils import timezone
from tests.browser.selenium_helpers import SeleniumTestCase
@@ -14,6 +14,8 @@ from tests.browser.selenium_helpers_base import Wait
from orm.models import Project, Build, Task, Recipe, Layer, Layer_Version
from bldcontrol.models import BuildRequest
from selenium.webdriver.common.by import By
class TestMostRecentBuildsStates(SeleniumTestCase):
""" Test states update correctly in most recent builds area """
@@ -62,7 +64,7 @@ class TestMostRecentBuildsStates(SeleniumTestCase):
element = self.wait_until_visible(selector)
bar_selector = '#recipes-parsed-percentage-bar-%s' % build.id
bar_element = element.find_element_by_css_selector(bar_selector)
bar_element = element.find_element(By.CSS_SELECTOR, bar_selector)
self.assertEqual(bar_element.value_of_css_property('width'), '0px',
'recipe parse progress should be at 0')
@@ -73,7 +75,7 @@ class TestMostRecentBuildsStates(SeleniumTestCase):
self.get(url)
element = self.wait_until_visible(selector)
bar_element = element.find_element_by_css_selector(bar_selector)
bar_element = element.find_element(By.CSS_SELECTOR, bar_selector)
recipe_bar_updated = lambda driver: \
bar_element.get_attribute('style') == 'width: 50%;'
msg = 'recipe parse progress bar should update to 50%'
@@ -107,7 +109,7 @@ class TestMostRecentBuildsStates(SeleniumTestCase):
element = self.wait_until_visible(selector)
bar_selector = '#build-pc-done-bar-%s' % build.id
bar_element = element.find_element_by_css_selector(bar_selector)
bar_element = element.find_element(By.CSS_SELECTOR, bar_selector)
task_bar_updated = lambda driver: \
bar_element.get_attribute('style') == 'width: 50%;'
@@ -121,7 +123,7 @@ class TestMostRecentBuildsStates(SeleniumTestCase):
self.get(url)
element = self.wait_until_visible(selector)
bar_element = element.find_element_by_css_selector(bar_selector)
bar_element = element.find_element(By.CSS_SELECTOR, bar_selector)
task_bar_updated = lambda driver: \
bar_element.get_attribute('style') == 'width: 100%;'
msg = 'tasks progress bar should update to 100%'
@@ -6,6 +6,7 @@
#
# SPDX-License-Identifier: GPL-2.0-only
#
from bldcontrol.models import BuildEnvironment
from django.urls import reverse
from tests.browser.selenium_helpers import SeleniumTestCase
@@ -18,6 +19,9 @@ class TestNewCustomImagePage(SeleniumTestCase):
CUSTOM_IMAGE_NAME = 'roopa-doopa'
def setUp(self):
BuildEnvironment.objects.get_or_create(
betype=BuildEnvironment.TYPE_LOCAL,
)
release = Release.objects.create(
name='baz',
bitbake_version=BitbakeVersion.objects.create(name='v1')
@@ -6,11 +6,13 @@
#
# SPDX-License-Identifier: GPL-2.0-only
#
import time
from django.urls import reverse
from tests.browser.selenium_helpers import SeleniumTestCase
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import InvalidElementStateException
from selenium.webdriver.common.by import By
from orm.models import Project, Release, BitbakeVersion
@@ -47,13 +49,14 @@ class TestNewProjectPage(SeleniumTestCase):
url = reverse('newproject')
self.get(url)
self.enter_text('#new-project-name', project_name)
select = Select(self.find('#projectversion'))
select.select_by_value(str(self.release.pk))
time.sleep(1)
self.click("#create-project-button")
time.sleep(2)
# We should get redirected to the new project's page with the
# notification at the top
@@ -84,6 +87,12 @@ class TestNewProjectPage(SeleniumTestCase):
select = Select(self.find('#projectversion'))
select.select_by_value(str(self.release.pk))
radio = self.driver.find_element(By.ID, 'type-new')
radio.click()
self.click("#create-project-button")
time.sleep(2)
element = self.wait_until_visible('#hint-error-project-name')
self.assertTrue(("Project names must be unique" in element.text),
@@ -96,6 +105,7 @@ class TestNewProjectPage(SeleniumTestCase):
except InvalidElementStateException:
pass
time.sleep(2)
self.assertTrue(
(Project.objects.filter(name=project_name).count() == 1),
"New project not found in database")
@@ -11,6 +11,7 @@ from django.urls import reverse
from tests.browser.selenium_helpers import SeleniumTestCase
from orm.models import BitbakeVersion, Release, Project, ProjectVariable
from selenium.webdriver.common.by import By
class TestProjectConfigsPage(SeleniumTestCase):
""" Test data at /project/X/builds is displayed correctly """
@@ -66,7 +67,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.enter_text('#new-imagefs_types', imagefs_type)
checkboxes = self.driver.find_elements_by_xpath("//input[@class='fs-checkbox-fstypes']")
checkboxes = self.driver.find_elements(By.XPATH, "//input[@class='fs-checkbox-fstypes']")
for checkbox in checkboxes:
if checkbox.get_attribute("value") == "btrfs":
@@ -95,7 +96,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
for checkbox in checkboxes:
if checkbox.get_attribute("value") == "cpio":
checkbox.click()
element = self.driver.find_element_by_id('new-imagefs_types')
element = self.driver.find_element(By.ID, 'new-imagefs_types')
self.wait_until_visible('#new-imagefs_types')
@@ -129,7 +130,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg)
# downloads dir path has a space
self.driver.find_element_by_id('new-dl_dir').clear()
self.driver.find_element(By.ID, 'new-dl_dir').clear()
self.enter_text('#new-dl_dir', '/foo/bar a')
element = self.wait_until_visible('#hintError-dl_dir')
@@ -137,7 +138,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
# downloads dir path starts with ${...} but has a space
self.driver.find_element_by_id('new-dl_dir').clear()
self.driver.find_element(By.ID,'new-dl_dir').clear()
self.enter_text('#new-dl_dir', '${TOPDIR}/down foo')
element = self.wait_until_visible('#hintError-dl_dir')
@@ -145,18 +146,18 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
# downloads dir path starts with /
self.driver.find_element_by_id('new-dl_dir').clear()
self.driver.find_element(By.ID,'new-dl_dir').clear()
self.enter_text('#new-dl_dir', '/bar/foo')
hidden_element = self.driver.find_element_by_id('hintError-dl_dir')
hidden_element = self.driver.find_element(By.ID,'hintError-dl_dir')
self.assertEqual(hidden_element.is_displayed(), False,
'downloads directory path valid but treated as invalid')
# downloads dir path starts with ${...}
self.driver.find_element_by_id('new-dl_dir').clear()
self.driver.find_element(By.ID,'new-dl_dir').clear()
self.enter_text('#new-dl_dir', '${TOPDIR}/down')
hidden_element = self.driver.find_element_by_id('hintError-dl_dir')
hidden_element = self.driver.find_element(By.ID,'hintError-dl_dir')
self.assertEqual(hidden_element.is_displayed(), False,
'downloads directory path valid but treated as invalid')
@@ -184,7 +185,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_START_TEXT in element.text), msg)
# path has a space
self.driver.find_element_by_id('new-sstate_dir').clear()
self.driver.find_element(By.ID, 'new-sstate_dir').clear()
self.enter_text('#new-sstate_dir', '/foo/bar a')
element = self.wait_until_visible('#hintError-sstate_dir')
@@ -192,7 +193,7 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
# path starts with ${...} but has a space
self.driver.find_element_by_id('new-sstate_dir').clear()
self.driver.find_element(By.ID,'new-sstate_dir').clear()
self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo')
element = self.wait_until_visible('#hintError-sstate_dir')
@@ -200,18 +201,18 @@ class TestProjectConfigsPage(SeleniumTestCase):
self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
# path starts with /
self.driver.find_element_by_id('new-sstate_dir').clear()
self.driver.find_element(By.ID,'new-sstate_dir').clear()
self.enter_text('#new-sstate_dir', '/bar/foo')
hidden_element = self.driver.find_element_by_id('hintError-sstate_dir')
hidden_element = self.driver.find_element(By.ID, 'hintError-sstate_dir')
self.assertEqual(hidden_element.is_displayed(), False,
'sstate directory path valid but treated as invalid')
# paths starts with ${...}
self.driver.find_element_by_id('new-sstate_dir').clear()
self.driver.find_element(By.ID, 'new-sstate_dir').clear()
self.enter_text('#new-sstate_dir', '${TOPDIR}/down')
hidden_element = self.driver.find_element_by_id('hintError-sstate_dir')
hidden_element = self.driver.find_element(By.ID, 'hintError-sstate_dir')
self.assertEqual(hidden_element.is_displayed(), False,
'sstate directory path valid but treated as invalid')
@@ -13,6 +13,7 @@ from django.urls import reverse
from django.utils import timezone
from tests.browser.selenium_helpers import SeleniumTestCase
from orm.models import BitbakeVersion, Release, Project, Build
from selenium.webdriver.common.by import By
class TestToasterTableUI(SeleniumTestCase):
"""
@@ -33,7 +34,7 @@ class TestToasterTableUI(SeleniumTestCase):
table: WebElement for a ToasterTable
"""
selector = 'thead a.sorted'
heading = table.find_element_by_css_selector(selector)
heading = table.find_element(By.CSS_SELECTOR, selector)
return heading.get_attribute('innerHTML').strip()
def _get_datetime_from_cell(self, row, selector):
@@ -45,7 +46,7 @@ class TestToasterTableUI(SeleniumTestCase):
selector: CSS selector to use to find the cell containing the date time
string
"""
cell = row.find_element_by_css_selector(selector)
cell = row.find_element(By.CSS_SELECTOR, selector)
cell_text = cell.get_attribute('innerHTML').strip()
return datetime.strptime(cell_text, '%d/%m/%y %H:%M')
@@ -105,7 +106,7 @@ class TestToasterTableUI(SeleniumTestCase):
self.click('#checkbox-started_on')
# sort by started_on column
links = table.find_elements_by_css_selector('th.started_on a')
links = table.find_elements(By.CSS_SELECTOR, 'th.started_on a')
for link in links:
if link.get_attribute('innerHTML').strip() == 'Started on':
link.click()