Javascript 编写一个脚本自动运行我的注册页面
我想写一个脚本,实际通过并输入注册表上的所有字段,然后点击register。我希望这每隔几分钟发生一次,然后我会在他们这样做之后立即删除它们。这是我试图绕过冷启动firebase调用的尝试 这是我的注册页面。我对这方面还比较陌生,所以我不知道从哪里开始,也不知道怎么做。顺便说一句,这是反应Javascript 编写一个脚本自动运行我的注册页面,javascript,node.js,reactjs,firebase,google-cloud-firestore,Javascript,Node.js,Reactjs,Firebase,Google Cloud Firestore,我想写一个脚本,实际通过并输入注册表上的所有字段,然后点击register。我希望这每隔几分钟发生一次,然后我会在他们这样做之后立即删除它们。这是我试图绕过冷启动firebase调用的尝试 这是我的注册页面。我对这方面还比较陌生,所以我不知道从哪里开始,也不知道怎么做。顺便说一句,这是反应 let firestore = firebase.firestore() const FormItem = Form.Item var userIDStripeSubmit = ""
let firestore = firebase.firestore()
const FormItem = Form.Item
var userIDStripeSubmit = ""
class RegistrationForm extends React.Component {
state = {
confirmDirty: false,
}
onSubmit = (event) => {
event.preventDefault();
this.props.form.validateFields((err, values) => {
if (err) return
const email = this.props.form.getFieldValue('email')
const passwordOne = this.props.form.getFieldValue('password1')
const firstName = this.props.form.getFieldValue('First Name')
const lastName = this.props.form.getFieldValue('Last Name')
const companyName = this.props.form.getFieldValue('Company Name')
const {
history,
} = this.props
AuthorizationHome.doCreateUserWithEmailAndPassword(email, passwordOne)
.then((authUser) => facades.userFacade().doCreateUser(authUser.user.uid, email))
.catch(error => {
this.setState({'error': error})
})
// adding into profiledata collection
// var userID = ""
firebase.auth().onAuthStateChanged((user) => {
if(user) {
console.log(user.uid)
userIDStripeSubmit = user.uid
console.log("userid inside firebase auth is" + user.uid)
// var firstNameFromField =
firestore.collection('profiledata').doc(user.uid).set({
firstname: firstName,
lastname: lastName,
companyname: companyName,
accountStatus: "inactive",
})
.catch(error => {
alert(error.message);
});
createCheckoutSession(user.uid)
}
})
// firestore collection query
})
}
handleConfirmBlur = (e) => {
const value = e.target.value;
this.setState({ confirmDirty: this.state.confirmDirty || !!value });
}
compareToFirstPassword = (rule, value, callback) => {
const form = this.props.form;
if (value && value !== form.getFieldValue('password1')) {
callback('Passwords do not match!');
} else {
callback();
}
}
validateToNextPassword = (rule, value, callback) => {
const form = this.props.form;
if (value && this.state.confirmDirty) {
form.validateFields(['password2'], { force: true });
}
callback();
}
render() {
const { getFieldDecorator } = this.props.form
const { error } = this.state
return (
<Form onSubmit={this.onSubmit} hideRequiredMark={true} className="registration-form" style={{ marginBottom: "0px" }}>
{ error && <Alert type="error" message={error.message}/> }
<FormItem label="Email" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('email', {
rules: [{
type: 'email', message: 'Invalid email address',
}, {
required: true, message: 'Please input your email address',
}],
})(
<Input placeholder="Enter email" />
)}
</FormItem>
{/* */}
<FormItem label="First Name" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('First Name', {
rules: [{
required: true, message: 'Please enter your First Name',
}],
})(
<Input type="text" placeholder="Enter Your First Name"/>
)}
</FormItem>
<FormItem label="Last Name" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('Last Name', {
rules: [{
required: true, message: 'Please enter your Last Name',
}],
})(
<Input type="text" placeholder="Enter Your Last Name"/>
)}
</FormItem>
<FormItem label="Company Name" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('Company Name', {
rules: [{
required: true, message: 'Please enter your Company Name',
}],
})(
<Input type="text" placeholder="Enter Your Company Name"/>
)}
</FormItem>
<FormItem label="Password" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('password1', {
rules: [{
required: true, message: 'Please choose a password',
}, {
validator: this.validateToNextPassword,
}],
})(
<Input type="password" placeholder="Enter password"/>
)}
</FormItem>
<FormItem label="Confirm Password" colon={false} style={{ marginBottom: "0px" }}>
{getFieldDecorator('password2', {
rules: [{
required: true, message: 'Please confirm your password',
}, {
validator: this.compareToFirstPassword,
}],
})(
<Input type="password" onBlur={this.handleConfirmBlur} placeholder="Confirm password" />
)}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" id="submitButton">Register</Button>
</FormItem>
</Form>
);
}
}
const WrappedRegistrationForm = Form.create()(RegistrationForm);
export default withRouter(WrappedRegistrationForm)
let-firestore=firebase.firestore()
const FormItem=表单项
var userIDStripeSubmit=“”
类注册表单扩展了React.Component{
状态={
confirmDirty:false,
}
onSubmit=(事件)=>{
event.preventDefault();
this.props.form.validateFields((错误,值)=>{
如果(错误)返回
const email=this.props.form.getFieldValue(“电子邮件”)
const passwordOne=this.props.form.getFieldValue('password1'))
const firstName=this.props.form.getFieldValue('First Name'))
const lastName=this.props.form.getFieldValue('Last Name')
const companyName=this.props.form.getFieldValue('公司名称')
常数{
历史
}=这是道具
AuthorizationHome.doCreateUserWithEmailAndPassword(电子邮件,passwordOne)
.then((authUser)=>facades.userFacade().doCreateUser(authUser.user.uid,电子邮件))
.catch(错误=>{
this.setState({'error':error})
})
//添加到profiledata收集中
//var userID=“”
firebase.auth().onAuthStateChanged((用户)=>{
如果(用户){
console.log(user.uid)
userIDStripeSubmit=user.uid
log(“firebase身份验证中的用户ID为”+user.uid)
//变量firstNameFromField=
firestore.collection('profiledata').doc(user.uid).set({
名字:名字,
lastname:lastname,
公司名称:公司名称,
帐户状态:“不活动”,
})
.catch(错误=>{
警报(错误消息);
});
createCheckoutSession(user.uid)
}
})
//firestore集合查询
})
}
HandleConfigerBlur=(e)=>{
常量值=e.target.value;
this.setState({confirmDirty:this.state.confirmDirty | |!!value});
}
compareToFirstPassword=(规则、值、回调)=>{
const form=this.props.form;
if(value&&value!==form.getFieldValue('password1')){
回调('密码不匹配!');
}否则{
回调();
}
}
ValidateNext密码=(规则、值、回调)=>{
const form=this.props.form;
if(值&&this.state.confirmDirty){
form.validateFields(['password2'],{force:true});
}
回调();
}
render(){
const{getFieldDecorator}=this.props.form
const{error}=this.state
返回(
{错误&&}
{getFieldDecorator('电子邮件'{
规则:[{
键入:“电子邮件”,消息:“无效电子邮件地址”,
}, {
必填项:true,消息:“请输入您的电子邮件地址”,
}],
})(
)}
{/* */}
{getFieldDecorator('名字'{
规则:[{
必填项:true,消息:“请输入您的名字”,
}],
})(
)}
{getFieldDecorator('姓氏'{
规则:[{
必填项:true,消息:“请输入您的姓氏”,
}],
})(
)}
{getFieldDecorator('公司名称'{
规则:[{
必填项:true,消息:“请输入您的公司名称”,
}],
})(
)}
{getFieldDecorator('password1'{
规则:[{
必需:true,消息:“请选择密码”,
}, {
validator:this.validateNext密码,
}],
})(
)}
{getFieldDecorator('password2'{
规则:[{
必填项:true,消息:“请确认您的密码”,
}, {
验证程序:此.compareToFirstPassword,
}],
})(
)}
登记
);
}
}
const WrappedRegistrationForm=Form.create()(RegistrationForm);
使用路由器导出默认值(WrappedRegistrationForm)
您可以使用访问页面,输入想要的值并提交表单。木偶演员在默认情况下是无头的,这意味着它在终端上运行而不需要打开浏览器
把ID放在你们的输入和按钮上,让木偶演员找到你们的输入/按钮。通过电子邮件,您将自动键入以下内容:
await page.type("#email", "email");
在您的项目上安装Puppeter:
npm install puppeteer --save
npm install cron --save
使用Puppeter自动提交页面表单的代码如下:
const puppeteer = require("puppeteer");
async function submitForm() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://yourpage.com", { waitUntil: "domcontentloaded" });
await page.type("#email", "email"); //First arg : ID of your input; Second arg the value that you want to input
await page.type("#firstName", "firstName");
await page.type("#lastName", "lastName");
await page.type("#companyName", "companyName");
// You could here on the value argument,
// if you have security concerns, use environment variables with process.env
await page.type("#password", "******");
await page.type("#confirmPassword", "******");
await page.click("#submit");
await browser.close();
}
之后,您可以将此逻辑放在CronJob上运行,使用类似的库
将其安装到您的项目中:
npm install puppeteer --save
npm install cron --save
当您使用Node.js在服务器上执行此代码时,每一分钟就会提交一次您的申请表。Hey Roger,这是您希望在后端使用cronjob或预定函数执行的操作。@Omar Hey!我感谢你的答复。我尝试使用CronJob,它呈现我的注册页面,我将其设置为使用用户ID和所有内容转到条带签出页面,但仍然发生(