我有这两个spec文件,但是当我要执行它们两个时,浏览器将打开angula.js Web,然后将切换到angularCal.js而不是完全不执行angular.js,我也尝试使用'src /test/*.js',它对我也不起作用。我尝试使用套件时遇到了同样的问题,当我分别执行它们时,它们可以正常工作。
//config
import {Config,browser} from 'protractor';
import{testConfig,platform} from 'protractor-html-reporter-2'
let HtmlScreenshotReporter = require('protractor-html-reporter-2');
let jasmineReporters = require('jasmine-reporters');
let reportsDirectory = './reports';
let dashboardReportDirectory = reportsDirectory + '/dashboardReport';
// An example configuration file
exports.config = {
// The address of a running selenium server.
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
//specs: ['src/test/angularCal.js','src/test/angular.js'],
specs: ['src/test/angularCal.js'],
//specs: ['*.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
},onPrepare: function () {
// xml report generated for dashboard
browser.manage().timeouts().implicitlyWait(5000);
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: reportsDirectory + '/xml',
filePrefix: 'xmlOutput'
}));
var fs = require('fs-extra');
if (!fs.existsSync(dashboardReportDirectory)) {
fs.mkdirSync(dashboardReportDirectory);
}
jasmine.getEnv().addReporter({
specDone: function (result) {
if (result.status == 'failed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
}else if(result.status == 'passed'){
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
}
}
});
},
onComplete: function () {
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
//let platform = caps.get('platform');
var HTMLReport = require('protractor-html-reporter-2');
let testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: dashboardReportDirectory,
outputFilename: 'index',
screenshotPath: './',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: false,
// testPlatform: platform
};
new HTMLReport().from(reportsDirectory + '/xml/xmlOutput.xml', testConfig);
});
},
};
//angular.js =spec 1
import { browser, by, element } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { angularsite } from "../pageobjects/angular_site";
describe('Angular site', function () {
let base = new BaseTest()
//browser.get(base.StartTest(2));
browser.get("https://material.angular.io/components/autocomplete/overview")
let ang = new angularsite();
it('Scrolldown', function () {
ang.scrollSettingSeprate();
})
it('Select Text (Alert)', function () {
ang.autocom(2, 2);
})
it('Checkbox', function () {
ang.checkboxtab();
ang.clickcheckbox();
})
it('DatePicker', function () {
ang.clickdatetab();
ang.clickdatemenu();
ang.clickcurrentdate()
})
it('Radiobutton', function () {
ang.clickradiobuttontab();
ang.clickradiobutton();
})
it('Slider', function () {
ang.clickslidertab()
ang.clicksliderop(3, 2, 3, 3)
})
it('Switch Alert', function () {
browser.get("http://www.way2automation.com/angularjs-protractor/banking/#/manager/addCust")
ang.alert(2)
})
it('Switch windows', function () {
browser.ignoreSynchronization = true;// for non angular sites
browser.get("https://skpatro.github.io/demo/links/")
ang.switch_windows()
})
})
angularCal.js = spec2
import { browser, element, by } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { datatable } from "../pageobjects/table_data";
import { calculator } from "../pageobjects/calculator_page";
describe('Calculator Page', function () {
let base = new BaseTest()
let calcu = new calculator();
beforeEach(function() {
calcu.clear_num1()
calcu.clear_num2()
});
afterEach(function() {
calcu.clear_num1()
calcu.clear_num2()
});
browser.get(base.StartTest(1))
it('Validate Caculator Page Addition feature', function () {
calcu.enter_num1(2)
calcu.addition_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(4);
})
it('Validate Caculator Page Subtraction feature', function () {
calcu.enter_num1(2)
calcu.subtract_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(5);
})
it('Validate Caculator Page Multiplication', function () {
calcu.enter_num1(11)
calcu.multi_Operator()
calcu.enter_num2(12)
calcu.click_Button();
calcu.validate_OutPut(4);
})
it('Validate Caculator Page Division',function(){
calcu.enter_num1(2)
calcu.division_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(7);
})
it('Validate Caculator Page Modulo',function(){
calcu.enter_num1(2)
calcu.modulo_Operator()
calcu.enter_num2(3)
calcu.click_Button();
calcu.validate_OutPut(8);
})
it('Get Table data', function () {
let table = new datatable()
table.get_dataTable();
})
})
答案 0 :(得分:2)
描述中的任何未包含在public class MainActivity extends AppCompatActivity {
private String token;
private String email;
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RequestQueue requestQueue;
private List<ListItem> listItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
Submit();
listItems = new ArrayList<>();
ListItemAdapter listItemAdapter = new ListItemAdapter(MainActivity.this, listItems);
recyclerView.setAdapter(listItemAdapter);
loadRecyclerViewData();
}
private void Submit() {
requestQueue = Volley.newRequestQueue((getApplicationContext()));
StringRequest postRequest = new StringRequest(Request.Method.POST, URL_DATA + "api-user-get",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject parentObject = new JSONObject(response);
JSONObject childObject = parentObject.getJSONObject("result");
token=childObject.getString("token");
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("email", "t1@gmail.com");
return params;
}
};
requestQueue.add(postRequest);
}
private void loadRecyclerViewData(){
StringRequest listRequest = new StringRequest(Request.Method.POST,URL_DATA+"api-spot-get-all",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray array = jsonObject.getJSONArray("result");
for (int i =0; i<array.length(); i++) {
JSONObject o = array.getJSONObject(i);
ListItem list = new ListItem(
o.getString("id"),
o.getString("name"),
o.getString("country"),
o.getString("whenToGo"),
o.getBoolean("isFavorite")
);
listItems.add(list);
}
adapter = new ListItemAdapter(getApplicationContext(), listItems);
recyclerView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
//
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
public Map<String, String> getHeaders() {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("token", "token");
return headers;
}
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("country", "");
params.put("windProbability", "");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(listRequest);
}
}
或其中一个钩子(beforeAll,beforeEach ...)中的代码都将在运行任何测试之前执行。这是茉莉花如何运作的意外行为之一。
您看到两个URL都被立即击中,因为两个browser.get都在测试之前运行。
您可以尝试将代码更改为以下
it
更新:稍微改变了结构
describe('Calculator Page', function () {
beforeAll(function(){
browser.get(base.StartTest(1))
})
})
答案 1 :(得分:1)
您可以在配置文件中使用套件:
suites: {
angular: './src/test/angular.js',
angularCal: './src/test/angularCal.js'
}