如何在SST Python中设置results_directory

时间:2014-11-25 18:58:07

标签: python selenium

我觉得这有点愚蠢,因为基本的selenium我没有问题保存截图,但是使用SST我使用take_screenshot('screenshot_name.png')它告诉我应该设置results_directory。问题是你如何设置results_directory。我找到的所有例子都将它设置为“NONE”,但这并不能满足我的测试需要。

以下是我的代码编写方式:

import unittest
from sst.actions import *
from sst import cases, config

config.results_directory = None

class TestMyTest(cases.SSTTestCase):

def test_mytestcase_home_page(self):
    go_to('http://www.mywebpage.com')
    assert_title_contains('MyWebPage')
    #Main page is displayed
    take_screenshot(filename='C/Users/Brenda/test/SST Test Project/results/home_page.png',add_timestamp=True)

1 个答案:

答案 0 :(得分:1)

我使用Google为我工作了以下脚本。诀窍是将结果目录添加到实际配置文件中,该文件位于@ {dir} \ Python27 \ Lib \ site-packages \ sst \ config.py并添加results_directory = "C:\Users\{me}\Desktop\Python-pip-SST\results"

import unittest
from sst.actions import *
from sst import cases, config

#config.results_directory = "C:\Users\{me}\Desktop\Python-pip-SST\results"

go_to('https://www.google.com/')
assert_title_contains('Google')
#Main page is displayed
take_screenshot(filename='home_page.png',add_timestamp=True)

并且,您还应该能够覆盖测试中的结果路径。您的工作代码应类似于以下内容

import unittest
from sst.actions import *
from sst import cases, config

#Just to be safe side try not to use any spaces in filename
config.results_directory = "C:/Users/Brenda/test/SSTTestProject/results"

class TestMyTest(cases.SSTTestCase):

def test_mytestcase_home_page(self):
    go_to('http://www.mywebpage.com')
    assert_title_contains('MyWebPage')
    #Main page is displayed
    take_screenshot(filename="home_page.png",add_timestamp=True)

我添加了屏幕截图,如果这对您有所帮助。更改filepath innconfig文件或从测试工作正常 enter image description here

相关问题