如何使用量角器 conf js 测试单独的环境名称? [英] how test separate environmental name with protractor conf js?

查看:18
本文介绍了如何使用量角器 conf js 测试单独的环境名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[

上图我正在运行 protractor Conf.js,具有特定的环境名称,存储在 JSON 文件中

The above pic i am run protractor Conf.js with particular environmental name which is stored in JSON file

如何仅在量角器测试用例中测试特定的环境 URL?

how to test particular environmental URL only in the protractor test case?

推荐答案

FIRST METHOD - 您必须在命令行中使用 params 变量传递参数.更新您的 conf.js 文件以包含名为 baseUrl 的参数和其他 url 变量,如下所示 -

FIRST METHOD - You have to pass the parameters using params variable in command line. Update your conf.js file to include a parameter called baseUrl and other url variables as shown below -

params: {
    baseUrl: "http://default_url" //provide your default url to be used
}

稍后在命令提示符中传递该值.方法如下-

later pass the value in the command prompt. Here's how -

protractor conf.js --params.baseUrl 'http://www.google.com'

无论您在哪里有代码来获取规范中的 url,请使用以下代码 -

Wherever you have code to get the url in your spec's, use the following code -

browser.get(browser.params.baseUrl);

第二种方法 - 如果您不想每次都将 url 传递给 params 对象,那么您可以将它们存储在 conf.js 中,甚至您的规格文件并调用它们.这是一个例子-

SECOND METHOD - If at all you don't want to pass the url to the params object everytime, then you can store them in your conf.js or even your specs file and call them. Here's an example -

你的 conf.js 文件 -

params: {
    baseUrl: ""
},
onPrepare: function(){
    switch(browser.params.baseUrl){
      case 'firsturl':
        browser.get("http://firsturl.com"); //replace firsturl with your actual url
        break;
      case 'secondurl':
        browser.get("http://www.secondurl.com");
        break;
      default:
        browser.get("http://www.defaulturl.com");
 }
}

现在通过命令行传递您要使用的 url -

Now pass the url's that you want to use through command line -

protractor conf.js --params.baseUrl 'firsturl' //to get first url
protractor conf.js //to open default url

第三种方法 - 如果您在运行具有许多规范的测试套件时遇到问题,在这种情况下,上述第二种方法将不起作用.您需要在每个测试规范文件中使用 browser.get(),在这种情况下使用以下方法 -

THIRD METHOD - If at all you have a problem of running a test suite with many spec's, in that case above second method wouldn't work. You need to use browser.get() in each of your test spec files, in such cases use following method -

更新您的 conf.js 文件 -

Update your conf.js file -

params: {
    baseUrl: "",
    url: ""
},
onPrepare: function(){
    switch(browser.params.baseUrl){
      case 'firsturl':
        browser.params.url = "http://firsturl.com"; //replace firsturl with your actual url
        break;
      case 'secondurl':
        browser.params.url = "http://www.secondurl.com";
        break;
      default:
        browser.params.url = "http://www.defaulturl.com";
 }
}

你的命令行命令 -

protractor conf.js --params.baseUrl 'firsturl' //to get first url
protractor conf.js //to open default url

您的测试规范文件需要包含 browser.get() 命令.方法如下-

Your test spec files need to include the browser.get() command. Here's how -

browser.get(browser.params.url);

希望对你有帮助.

这篇关于如何使用量角器 conf js 测试单独的环境名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆