iframe을 사용하여 웹 사이트를 테스트 할 수있는 Node.js로 오이 테스트 설정을하려고합니다. 일반적으로 iframe은 스크립트 간 보안 제한으로 인해 사용하지 않습니다. 그러나 가능한 경우 (나는 확신합니다. 그리고 솔루션을 생각해내는 것이 맞습니다.) 특정 URL 이름이 요청 될 때 요청 된 URL을 통해 테스트 대상 웹 사이트를 가져 오는 것입니다. iframe에 테스트 대상의 복사본이로드됩니다. 기본적으로 주소 요청 라우터와 비슷한 req.url 을 기반으로 특정 페이지를 가져 오는 표준 node.js 서버입니다.Node.js를 통해 http 요청 라우팅하기
정확히 여기에 맹렬한 시도가 있습니다. 을 통해 테스트 페이지를 가져 오는 중입니다. URL이 작동합니다. 하지만 HTTP 서버에서 연결 개체로 전환하는 데 문제가 있습니다. http 서버 응답으로 연결을 "공급"할 수 있습니까?
추신. 또한 두 개의 node.js 서버로 솔루션을 만들었습니다. 노드 1이 테스트 대상을 가져 와서 오이 테스트 페이지와 섞습니다. 노드 2가 오이 테스트를 호스팅합니다. 이 해결책이 효과적입니다. 그러나 자바 스크립트 이름 충돌이 발생하는 웹 사이트에서는 문제가 발생합니다. 그래서 캡슐화로이 문제를 해결하는 iframe 솔루션이 더 매력적입니다.
var http = require('http');
var connect = require('connect');
var port = process.env.PORT || 8788;
var server = http.createServer(function(req, webres)
{
var url = req.url;
console.log(url);
if(url == '/myWebsiteToBeTestedWithCucumberJS')
{
// Load the web site to be tested "myWebsiteToBeTestedWithCucumberJS"
// And update the references
// Finaly write the page with the webres
// The page will appear to be hosted locally
console.log('Loading myWebsiteToBeTestedWithCucumberJS');
webres.writeHead(200, {'content-type': 'text/html, level=1'});
var options =
{
host: 'www.myWebsiteToBeTestedWithCucumberJS.com,
port: 80,
path: '/'
};
var page = '';
var req = http.get(options, function(res)
{
console.log("Got response: " + res.statusCode);
res.on('data', function(chunk)
{
page = page + chunk;
});
res.on('end', function()
{
// Change relative paths to absolute (actual web location where images, javascript and stylesheets is placed)
page = page.replace(/ href="\/\//g , ' href="/');
page = page.replace(/ src="\//g , ' src="www.myWebsiteToBeTestedWithCucumberJS.com');
page = page.replace(/ data-src="\//g , ' data-src="www.myWebsiteToBeTestedWithCucumberJS.com');
page = page.replace(/ href="\//g , ' href="www.myWebsiteToBeTestedWithCucumberJS.com');
webres.write(page);
webres.end('');
});
});
}
else
{
// Load any file from localhost:8788
// This is where the cucumber.js project files are hosted
var dirserver = connect.createServer();
var browserify = require('browserify');
var cukeBundle = browserify({
mount: '/cucumber.js',
require: ['cucumber-html', './lib/cucumber', 'gherkin/lib/gherkin/lexer/en'],
ignore: ['./cucumber/cli', 'connect']
});
dirserver.use(connect.static(__dirname));
dirserver.use(cukeBundle);
dirserver.listen(port);
}
}).on('error', function(e)
{
console.log("Got error: " + e.message);
});
server.listen(port);
console.log('Accepting connections on port ' + port + '...');
부수적으로 Cukestall (https://github.com/jbpros/cukestall)을 살펴 보시기 바랍니다. Cucumber.js의 잠재적 인 공식 iframe 러너입니다. local * Node.js 응용 프로그램을 테스트하기위한 것입니다. 그러나 * 원격 * 응용 프로그램에서 기능을 실행하고로드하는 것이 매우 쉽습니다. – jbpros
에는 'loadMyWebsiteToBeTestedWithCucumberJS' 함수 이름에 대한 upvote가 있습니다. –