-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.py
executable file
·269 lines (251 loc) · 8.48 KB
/
select.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import jsonrpclib
import sys
class BasicTab(unittest.TestCase):
args = sys.argv[1].split(" ")
# args[0] --- radio_url
# args[1] --- browser
# args[2] --- webinterface*.sh
# args[3] --- name of element
# args[4] --- value
def setUp(self):
args = self.args
self.getBrowser(args[1]) #setup browser
self.driver.implicitly_wait(30)
self.base_url = "http://" + args[0] + "/" #set base radio_url
self.verificationErrors = []
self.accept_next_alert = True
def getBrowser(self, browser):
if browser == "firefox" or browser == "Firefox":
self.driver = webdriver.Firefox()
elif browser == "chrome" or browser == "Chrome":
self.driver = webdriver.Chrome()
elif browser == "ie" or browser == "IE":
print "No IE on Linux"
else:
self.driver = webdriver.Frefox()
def test_basic(self):
args = self.args
#go to url and find select element
self.driver.get(self.base_url + args[2])
#find select element and click
self.clickSelect(args[3], args[4])
#click button to submit form
self.submitForm(args[3])
#check value on radio
rResult = self.getRadioValue(args[0], args[3])
#convert value to text
rResult = self.convertValue2Text(rResult, args[3])
#write result into output file
self.writeToFile(rResult, args[3], args[4])
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
def clickSelect(self, element, value):
selectElement = Select(self.driver.find_element_by_name(element))
#go through select options
for option in selectElement.options:
text = option.text
strtext = text.encode('ascii', 'ignore') #convert unicode
value = value.upper()
strtext = strtext.upper()
#match all options
if element == "temp_reporting_mode" or element == "phytest" or element == "parity":
if value in strtext:
print "click " + strtext
option.click()
break
else:
strtext = strtext.split(" ")[0]
if element == "class0_mcs":
strtext - strtext.split(":")[0]
if value == strtext:
print "click " + strtext + "\n"
option.click()
break
else:
if value == strtext:
print "click " + strtext + "\n"
option.click()
break
def clickButton(self, buttonName):
#click on submit button, double to make it wait
xpath = "(//input[@name='" + buttonName + "'])[1]"
self.driver.find_element_by_xpath(xpath).click()
self.driver.find_element_by_xpath(xpath).click()
def submitForm(self, element):
if element == "freq" or element == "bandwidth":
self.clickButton("checkpage0")
elif element == "power_mw":
self.clickButton("checkpage1")
elif element == "gateway_disable":
self.clickButton("checkpage2")
#webinterface2
elif element == "rts_disable" or element == "aggr_thresh" or element == "max_speed" or element == "burst_time" or element == "enc_disable" or element == "enc_key_len" or element == "class0_mcs" or element == "phytest":
self.clickButton("advance1")
elif element == "vir_ip_disable" or element == "vpn_disable":
self.clickButton("advance2")
#webinterface5
#elif element == "serial_mode":
# self.clickButton("mode_change")
elif element == "baud_rate" or element == "char_size" or element == "parity" or element == "stop_bits" or element == "sw_flow_control" or element == "hw_flow_control" or element == "proto":
self.clickButton("advance")
#webinterface7
elif element == "temp_reporting_mode":
self.clickButton("checkpage0")
elif element == "rssi_report_enable":
self.clickButton("checkpage1")
def getRadioValue(self, radio_url, element):
#using jsonrpclib to get value from radio
jsonrpc_url = "http://" + radio_url + "/streamscape_api"
server = jsonrpclib.Server(jsonrpc_url)
if element == "freq":
radioResult = server.freq()
elif element == "bandwidth":
radioResult = server.bw()
elif element == "power_mw":
radioResult = server.power_dBm()
elif element == "gateway_disable":
radioResult = server.wbg_disable()
#webinterface2
elif element == "rts_disable":
radioResult = server.rts_disable()
elif element == "aggr_thresh":
radioResult = server.aggr_thresh()
elif element == "max_speed":
radioResult = server.max_speed()
elif element == "burst_time":
radioResult = server.burst_time()
elif element == "enc_disable":
radioResult = server.enc_disable()
elif element == "enc_key_len":
radioResult = server.enc_key_len()
elif element == "class0_mcs":
radioResult = server.mcs()
elif element == "phytest":
radioResult = server.radio_mode()
elif element == "vir_ip_disable":
radioResult = server.virtual_ip_disable()
elif element == "vpn_disable":
radioResult = server.vpn_disable()
#webinterface5.sh
#elif element == "serial_mode":
elif element == "baud_rate" or element == "char_size" or element == "parity" or element == "stop_bits" or element == "sw_flow_control" or element == "hw_flow_control" or element == "proto":
radioResult = server.serial_config()
#webinterface7.sh
elif element == "temp_reporting_mode":
radioResult = server.temp_reporting_mode()
elif element == "rssi_report_enable":
radioResult = server.rssi_report_enable()
#convert unicode
if element == "baud_rate":
rResult = radioResult[0].encode('ascii', 'ignore')
elif element == "char_size":
rResult = radioResult[1].encode('ascii', 'ignore')
elif element == "parity":
rResult = radioResult[2].encode('ascii', 'ignore')
elif element == "stop_bits":
rResult = radioResult[3].encode('ascii', 'ignore')
elif element == "sw_flow_control":
rResult = radioResult[5].encode('ascii', 'ignore')
elif element == "hw_flow_control":
rResult = radioResult[4].encode('ascii', 'ignore')
elif element == "proto":
rResult = radioResult[7].encode('ascii', 'ignore')
else:
rResult = radioResult[0].encode('ascii', 'ignore')
return rResult
def convertValue2Text(self, rResult, element):
#convert 0/1 to Enable/Disable
if element == "gateway_disable" or element == "vpn_disable" or element == "vir_ip_disable" or element == "enc_disable" or element == "rts_disable":
if rResult == "0":
rResult = "Enable"
else:
rResult = "Disable"
elif element == "class0_mcs":
if rResult == "255":
rResult = "Auto"
elif element == "parity":
if rResult == "0":
rResult = "Even"
elif rResult == "1":
rResult = "Odd"
elif rResult == "2":
rResult = "None"
elif element == "stop_bits":
if rResult == "0":
rResult = "1"
elif rResult == "1":
rResult = "2"
elif element == "sw_flow_control" or element == "hw_flow_control":
if rResult == "1":
rResult = "Enable"
elif rResult == "0":
rResult = "Disable"
elif element == "proto":
rResult = rResult.upper()
elif element == "phytest":
if rResutl == "1":
rResult == "PHY"
elif rResult == "0":
rResult == "NETWORK"
elif element == "temp_reporting_mode":
if rResult == "0":
rResult = "Disable"
elif rResult == "1":
rResult = "heating"
elif rResult == "2":
rResult = "periodically"
elif element == "rssi_report_enable":
if rResult == "0":
rResult = "Disable"
elif rResult == "1":
rResult = "Enable"
elif element == "burst_time":
rResult = int(rResult)
rResult = rResult / 1000
rResult = str(rResult)
return rResult
def writeToFile(self, rResult, element, value):
rResult = rResult.upper()
value = value.upper()
f = open('outputfile', 'a')
if rResult == value:
print element + " "
print rResult
print "updated correctly\n"
else:
print element + " "
print rResult
print "! wrong !\n"
f.write("wrong! " + element + "\n")
f.write("radio value is " + rResult)
f.write("; test value is " + value)
f.write("\n")
f.close()
if __name__ == "__main__":
unittest.main(argv=sys.argv[1:])