update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / ra / pytest / ns / gui_tests / conftest.py
1 #!/usr/bin/env python
2 # Copyright 2017 RIFT.IO Inc
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 import gi
18 import pytest
19 import os
20 from pyvirtualdisplay import Display
21 from selenium import webdriver
22 from selenium.webdriver.support.ui import WebDriverWait
23 from selenium.webdriver.support import expected_conditions as EC
24 from selenium.webdriver.common.by import By
25
26 gi.require_version('RwCloudYang', '1.0')
27 gi.require_version('RwConfigAgentYang', '1.0')
28 gi.require_version('RwSdnYang', '1.0')
29
30 from gi.repository import (
31 RwSdnYang,
32 RwCloudYang,
33 RwConfigAgentYang,
34 )
35
36 gi.require_version('RwKeyspec', '1.0')
37 from gi.repository.RwKeyspec import quoted_key
38
39
40 @pytest.fixture(scope='session')
41 def cloud_proxy(mgmt_session):
42 """cloud_proxy."""
43 return mgmt_session.proxy(RwCloudYang)
44
45
46 @pytest.fixture(scope='session')
47 def sdn_proxy(mgmt_session):
48 """sdn_proxy."""
49 return mgmt_session.proxy(RwSdnYang)
50
51
52 @pytest.fixture(scope='session')
53 def config_agent_proxy(mgmt_session):
54 """config_agent_proxy."""
55 return mgmt_session.proxy(RwConfigAgentYang)
56
57
58 @pytest.fixture(scope='session')
59 def driver(request, confd_host, logger):
60 """Set up virtual diplay and browser driver."""
61 # Set up the virtual display
62 display = Display(visible=0, size=(1024, 768))
63 display.start()
64
65 logger.info("Initializing the chrome web driver")
66 root_dir = os.environ.get('RIFT_ROOT')
67 webdriver_path = '{}/chromedriver'.format(root_dir)
68 # webdriver_path = os.environ["webdriver.chrome.driver"]
69 # Something like this should be implemented.
70
71 driver_ = webdriver.Chrome(executable_path=webdriver_path)
72 driver_.implicitly_wait(5)
73 url = "http://{}:8000/".format(confd_host)
74 logger.info("Getting the URL {}".format(url))
75 driver_.get(url)
76 WebDriverWait(driver_, 10).until(
77 EC.presence_of_element_located((By.CLASS_NAME, "logo"))
78 )
79
80 logger.info("Signing into the Rift home page")
81 driver_.find_element_by_name("username").send_keys("admin")
82 driver_.find_element_by_name("password").send_keys("admin")
83 driver_.find_element_by_id("submit").click()
84 WebDriverWait(driver_, 10).until(
85 EC.presence_of_element_located((By.CLASS_NAME, "skyquakeNav"))
86 )
87
88 def teardown():
89 driver_.quit()
90 display.stop()
91
92 yield driver_