1#! /usr/bin/env python3
2#
3# BitBake Toaster functional tests implementation
4#
5# Copyright (C) 2017 Intel Corporation
6#
7# SPDX-License-Identifier: GPL-2.0-only
8#
9
10import re
11from django.urls import reverse
12import pytest
13from tests.functional.functional_helpers import SeleniumFunctionalTestCase
14from orm.models import Project
15from selenium.webdriver.common.by import By
16
17from tests.functional.utils import get_projectId_from_url
18
19
20@pytest.mark.django_db
21@pytest.mark.order("second_to_last")
22class FuntionalTestBasic(SeleniumFunctionalTestCase):
23    """Basic functional tests for Toaster"""
24    project_id = None
25
26    def setUp(self):
27        super(FuntionalTestBasic, self).setUp()
28        if not FuntionalTestBasic.project_id:
29            self._create_slenium_project()
30            current_url = self.driver.current_url
31            FuntionalTestBasic.project_id = get_projectId_from_url(current_url)
32
33#   testcase (1514)
34    def _create_slenium_project(self):
35        project_name = 'selenium-project'
36        self.get(reverse('newproject'))
37        self.wait_until_visible('#new-project-name', poll=3)
38        self.driver.find_element(By.ID, "new-project-name").send_keys(project_name)
39        self.driver.find_element(By.ID, 'projectversion').click()
40        self.driver.find_element(By.ID, "create-project-button").click()
41        element = self.wait_until_visible('#project-created-notification', poll=10)
42        self.assertTrue(self.element_exists('#project-created-notification'),'Project creation notification not shown')
43        self.assertTrue(project_name in element.text,
44                        "New project name not in new project notification")
45        self.assertTrue(Project.objects.filter(name=project_name).count(),
46                        "New project not found in database")
47        return Project.objects.last().id
48
49 #  testcase (1515)
50    def test_verify_left_bar_menu(self):
51        self.get(reverse('all-projects'))
52        self.wait_until_present('#projectstable', poll=10)
53        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
54        self.wait_until_present('#config-nav', poll=10)
55        self.assertTrue(self.element_exists('#config-nav'),'Configuration Tab does not exist')
56        project_URL=self.get_URL()
57        self.driver.find_element(By.XPATH, '//a[@href="'+project_URL+'"]').click()
58        self.wait_until_present('#config-nav', poll=10)
59
60        try:
61            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'customimages/"'+"]").click()
62            self.wait_until_present('#config-nav', poll=10)
63            self.assertTrue(re.search("Custom images",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'Custom images information is not loading properly')
64        except:
65            self.fail(msg='No Custom images tab available')
66
67        try:
68            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'images/"'+"]").click()
69            self.wait_until_present('#config-nav', poll=10)
70            self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible image recipes information is not loading properly')
71        except:
72            self.fail(msg='No Compatible image tab available')
73
74        try:
75            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'softwarerecipes/"'+"]").click()
76            self.wait_until_present('#config-nav', poll=10)
77            self.assertTrue(re.search("Compatible software recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible software recipe information is not loading properly')
78        except:
79            self.fail(msg='No Compatible software recipe tab available')
80
81        try:
82            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'machines/"'+"]").click()
83            self.wait_until_present('#config-nav', poll=10)
84            self.assertTrue(re.search("Compatible machines",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible machine information is not loading properly')
85        except:
86            self.fail(msg='No Compatible machines tab available')
87
88        try:
89            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'layers/"'+"]").click()
90            self.wait_until_present('#config-nav', poll=10)
91            self.assertTrue(re.search("Compatible layers",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible layer information is not loading properly')
92        except:
93            self.fail(msg='No Compatible layers tab available')
94
95        try:
96            self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'configuration"'+"]").click()
97            self.wait_until_present('#config-nav', poll=10)
98            self.assertTrue(re.search("Bitbake variables",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Bitbake variables information is not loading properly')
99        except:
100            self.fail(msg='No Bitbake variables tab available')
101
102#   testcase (1516)
103    def test_review_configuration_information(self):
104        self.get(reverse('all-projects'))
105        self.wait_until_present('#projectstable', poll=10)
106        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
107        project_URL=self.get_URL()
108        self.wait_until_present('#config-nav', poll=10)
109        try:
110           self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist')
111           self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.XPATH, "//span[@id='project-machine-name']").text),'The machine type is not assigned')
112           self.driver.find_element(By.XPATH, "//span[@id='change-machine-toggle']").click()
113           self.wait_until_visible('#select-machine-form', poll=10)
114           self.wait_until_visible('#cancel-machine-change', poll=10)
115           self.driver.find_element(By.XPATH, "//form[@id='select-machine-form']/a[@id='cancel-machine-change']").click()
116        except:
117           self.fail(msg='The machine information is wrong in the configuration page')
118
119        try:
120           self.driver.find_element(By.ID, 'no-most-built')
121        except:
122           self.fail(msg='No Most built information in project detail page')
123
124        try:
125           self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.XPATH, "//span[@id='project-release-title']").text),'The project release is not defined')
126        except:
127           self.fail(msg='No project release title information in project detail page')
128
129        try:
130           self.driver.find_element(By.XPATH, "//div[@id='layer-container']")
131           self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count')
132           layer_list = self.driver.find_element(By.ID, "layers-in-project-list")
133           layers = layer_list.find_elements(By.TAG_NAME, "li")
134           for layer in layers:
135               if re.match ("openembedded-core",layer.text):
136                    print ("openembedded-core layer is a default layer in the project configuration")
137               elif re.match ("meta-poky",layer.text):
138                  print ("meta-poky layer is a default layer in the project configuration")
139               elif re.match ("meta-yocto-bsp",layer.text):
140                  print ("meta-yocto-bsp is a default layer in the project configuratoin")
141               else:
142                  self.fail(msg='default layers are missing from the project configuration')
143        except:
144           self.fail(msg='No Layer information in project detail page')
145
146#   testcase (1517)
147    def test_verify_machine_information(self):
148        self.get(reverse('all-projects'))
149        self.wait_until_present('#projectstable', poll=10)
150        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
151        self.wait_until_present('#config-nav', poll=10)
152
153        try:
154            self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist')
155            self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.ID, "project-machine-name").text),'The machine type is not assigned')
156            self.driver.find_element(By.ID, "change-machine-toggle").click()
157            self.wait_until_visible('#select-machine-form', poll=10)
158            self.wait_until_visible('#cancel-machine-change', poll=10)
159            self.driver.find_element(By.ID, "cancel-machine-change").click()
160        except:
161            self.fail(msg='The machine information is wrong in the configuration page')
162
163#   testcase (1518)
164    def test_verify_most_built_recipes_information(self):
165        self.get(reverse('all-projects'))
166        self.wait_until_present('#projectstable', poll=10)
167        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
168        self.wait_until_present('#config-nav', poll=10)
169        project_URL=self.get_URL()
170        try:
171            self.assertTrue(re.search("You haven't built any recipes yet",self.driver.find_element(By.ID, "no-most-built").text),'Default message of no builds is not present')
172            self.driver.find_element(By.XPATH, "//div[@id='no-most-built']/p/a[@href="+'"'+project_URL+'images/"'+"]").click()
173            self.wait_until_present('#config-nav', poll=10)
174            self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Choose a recipe to build link  is not working  properly')
175        except:
176            self.fail(msg='No Most built information in project detail page')
177
178#   testcase (1519)
179    def test_verify_project_release_information(self):
180        self.get(reverse('all-projects'))
181        self.wait_until_present('#projectstable', poll=10)
182        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
183        self.wait_until_present('#config-nav', poll=10)
184
185        try:
186            self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.ID, "project-release-title").text),'The project release is not defined')
187        except:
188            self.fail(msg='No project release title information in project detail page')
189
190#   testcase (1520)
191    def test_verify_layer_information(self):
192        self.get(reverse('all-projects'))
193        self.wait_until_present('#projectstable', poll=10)
194        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
195        self.wait_until_present('#config-nav', poll=10)
196        project_URL=self.get_URL()
197        try:
198           self.driver.find_element(By.XPATH, "//div[@id='layer-container']")
199           self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count')
200           layer_list = self.driver.find_element(By.ID, "layers-in-project-list")
201           layers = layer_list.find_elements(By.TAG_NAME, "li")
202
203           for layer in layers:
204               if re.match ("openembedded-core",layer.text):
205                    print ("openembedded-core layer is a default layer in the project configuration")
206               elif re.match ("meta-poky",layer.text):
207                  print ("meta-poky layer is a default layer in the project configuration")
208               elif re.match ("meta-yocto-bsp",layer.text):
209                  print ("meta-yocto-bsp is a default layer in the project configuratoin")
210               else:
211                  self.fail(msg='default layers are missing from the project configuration')
212
213           self.driver.find_element(By.XPATH, "//input[@id='layer-add-input']")
214           self.driver.find_element(By.XPATH, "//button[@id='add-layer-btn']")
215           self.driver.find_element(By.XPATH, "//div[@id='layer-container']/form[@class='form-inline']/p/a[@id='view-compatible-layers']")
216           self.driver.find_element(By.XPATH, "//div[@id='layer-container']/form[@class='form-inline']/p/a[@href="+'"'+project_URL+'importlayer"'+"]")
217        except:
218            self.fail(msg='No Layer information in project detail page')
219
220#   testcase (1521)
221    def test_verify_project_detail_links(self):
222        self.get(reverse('all-projects'))
223        self.wait_until_present('#projectstable', poll=10)
224        self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click()
225        self.wait_until_present('#config-nav', poll=10)
226        project_URL=self.get_URL()
227        self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li[@id='topbar-configuration-tab']/a[@href="+'"'+project_URL+'"'+"]").click()
228        self.wait_until_present('#config-nav', poll=10)
229        self.assertTrue(re.search("Configuration",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li[@id='topbar-configuration-tab']/a[@href="+'"'+project_URL+'"'+"]").text), 'Configuration tab in project topbar is misspelled')
230
231        try:
232            self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").click()
233            self.wait_until_visible('#project-topbar', poll=10)
234            self.assertTrue(re.search("Builds",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").text), 'Builds tab in project topbar is misspelled')
235            self.driver.find_element(By.XPATH, "//div[@id='empty-state-projectbuildstable']")
236        except:
237            self.fail(msg='Builds tab information is not present')
238
239        try:
240            self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").click()
241            self.wait_until_visible('#project-topbar', poll=10)
242            self.assertTrue(re.search("Import layer",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").text), 'Import layer tab in project topbar is misspelled')
243            self.driver.find_element(By.XPATH, "//fieldset[@id='repo-select']")
244            self.driver.find_element(By.XPATH, "//fieldset[@id='git-repo']")
245        except:
246            self.fail(msg='Import layer tab not loading properly')
247
248        try:
249            self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").click()
250            self.wait_until_visible('#project-topbar', poll=10)
251            self.assertTrue(re.search("New custom image",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").text), 'New custom image tab in project topbar is misspelled')
252            self.assertTrue(re.search("Select the image recipe you want to customise",self.driver.find_element(By.XPATH, "//div[@class='col-md-12']/h2").text),'The new custom image tab is not loading correctly')
253        except:
254            self.fail(msg='New custom image tab not loading properly')
255
256
257
258