Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何建立一个关键字,这样我就不会';在使用seleniumlibrary的robot框架测试用例中,您不必运行登录到web的所有功能吗?_Selenium_Authentication_Robotframework_Data Driven Tests - Fatal编程技术网

如何建立一个关键字,这样我就不会';在使用seleniumlibrary的robot框架测试用例中,您不必运行登录到web的所有功能吗?

如何建立一个关键字,这样我就不会';在使用seleniumlibrary的robot框架测试用例中,您不必运行登录到web的所有功能吗?,selenium,authentication,robotframework,data-driven-tests,Selenium,Authentication,Robotframework,Data Driven Tests,我想在我关于测试的主题的最后一个项目中测试网站的功能。我是这个领域的初学者,不知道如何在robot框架中创建关键字,所以我不必在我要测试的所有功能中包含登录部分 正如您在我的示例代码中所看到的,在我要测试的每个特性中,我必须首先从登录部分开始。实际上,我将测试10个特性 我需要实现的是,我不必总是登录每个功能,这意味着它减少了过程,因此我可以跳转到我要测试的功能。我的意思是,我有登录功能,处理所有的功能 如果我的问题是关于困惑的,请原谅。 我在下面提供这些示例代码,以使您了解我的问题 *** S

我想在我关于测试的主题的最后一个项目中测试网站的功能。我是这个领域的初学者,不知道如何在robot框架中创建关键字,所以我不必在我要测试的所有功能中包含登录部分

正如您在我的示例代码中所看到的,在我要测试的每个特性中,我必须首先从登录部分开始。实际上,我将测试10个特性

我需要实现的是,我不必总是登录每个功能,这意味着它减少了过程,因此我可以跳转到我要测试的功能。我的意思是,我有登录功能,处理所有的功能

如果我的问题是关于困惑的,请原谅。 我在下面提供这些示例代码,以使您了解我的问题

*** Settings ***

 Library    SeleniumLibrary

*** Test Cases ***

 LoginTest

Open Browser    *website-url*    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3

Log    Task Completed   
视图剖面测试

Open Browser    *website-url*    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Sleep    1
Click Element    //*[@id="sidebar-me"]/ul[1]/li[3]/a
*** Settings ***
Test Setup       LoginTest
Test Teardown    LogoutTest

*** Test Cases ***
TestFeature#1
    [Documentation]    Setup and teardown from setting table
    Do Something
视图历史测试

Open Browser    *website-url    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password    
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Sleep    1
Click Element    //*[@id="sidebar-me"]/ul[1]/li[3]/a
Sleep    1
Click Element    //*[@id="user-mycred-history"]
*** Settings ***
Test Setup       LoginTest
Test Teardown    LogoutTest

*** Test Cases ***
TestFeature#1
    [Documentation]    Setup and teardown from setting table
    Do Something

我想要实现的是:登录一次,测试所有功能,而不登录每个功能

这是解决问题的方法之一

步骤1:-创建 在本例中,将所有常用函数保留在此文件中,例如Login关键字,现在,所有测试都将通过在各自的测试用例文件中使用测试设置来调用此函数

*** Keywords ***
LoginTest

Open Browser    *website-url*    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3

Log    Task Completed 
在这里,在第2步和第3步中,每次都会由包含测试设置LoginTest的每个文件下创建的相应测试用例调用在_____________; init.robot文件中仅创建一次的登录和注销关键字。 注意,在您的testcase文件中,您没有重复相同的登录代码,而是使用测试设置为每个测试用例调用登录特性

步骤2:-查看配置文件测试

Open Browser    *website-url*    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Sleep    1
Click Element    //*[@id="sidebar-me"]/ul[1]/li[3]/a
*** Settings ***
Test Setup       LoginTest
Test Teardown    LogoutTest

*** Test Cases ***
TestFeature#1
    [Documentation]    Setup and teardown from setting table
    Do Something
步骤3:-查看历史测试

Open Browser    *website-url    chrome
Set Selenium Implicit Wait    5
Sleep    2
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Input Text    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[1]/input    username
Input Password    xpath=//*[@id="login_register_form"]/div[1]/form/div[1]/div[2]/input   password    
Click Element    xpath=//*[@id="sidebar-wp-submit"] 
Sleep    3
Click Element    //*[@id="headertop"]/div/div/div[2]/ul[1]/li[1]/a
Sleep    1
Click Element    //*[@id="sidebar-me"]/ul[1]/li[3]/a
Sleep    1
Click Element    //*[@id="user-mycred-history"]
*** Settings ***
Test Setup       LoginTest
Test Teardown    LogoutTest

*** Test Cases ***
TestFeature#1
    [Documentation]    Setup and teardown from setting table
    Do Something

1.StackOverflow不是用来做家庭作业的,但因为你要求的是一件具体的事情,我想我们会破例2。我不确定,你所说的“关键字”是什么意思,因为我没有使用它。我建议阅读框架文档+解决它的好运气:),祝你好运谢谢你的建议,伙计,我很感激